Merge pull request #1350 from open-metadata/issue1349

Fixes #1349 - Make service entity PUT request consistent with other e…
This commit is contained in:
Suresh Srinivas 2021-11-23 19:22:05 -08:00 committed by GitHub
commit d339e651f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 294 additions and 368 deletions

View File

@ -38,8 +38,6 @@ import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ServerProperties;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.statement.SqlLogger;
import org.jdbi.v3.core.statement.StatementContext;
import org.openmetadata.catalog.events.EventFilter;
import org.openmetadata.catalog.exception.CatalogGenericExceptionMapper;
import org.openmetadata.catalog.exception.ConstraintViolationExceptionMapper;
@ -62,7 +60,6 @@ import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.time.temporal.ChronoUnit;
/**
* Main catalog application
@ -174,7 +171,7 @@ public class CatalogApplication extends Application<CatalogApplicationConfig> {
}
}
private void registerResources(CatalogApplicationConfig config, Environment environment, Jdbi jdbi) throws IOException {
private void registerResources(CatalogApplicationConfig config, Environment environment, Jdbi jdbi) {
CollectionRegistry.getInstance().registerResources(jdbi, environment, config, authorizer);
environment.lifecycle().manage(new Managed() {

View File

@ -49,6 +49,7 @@ public class CatalogGenericExceptionMapper implements ExceptionMapper<Throwable>
@Override
public Response toResponse(Throwable ex) {
LOG.info("Exception ", ex);
if (ex instanceof ProcessingException || ex instanceof IllegalArgumentException) {
final Response response = BadRequestException.of().getResponse();
return Response.fromResponse(response)

View File

@ -36,6 +36,7 @@ import java.util.stream.Collectors;
public class ConstraintViolationExceptionMapper implements ExceptionMapper<ConstraintViolationException> {
@Override
public Response toResponse(ConstraintViolationException exception) {
System.out.println(exception);
Set<ConstraintViolation<?>> constraintViolations = exception.getConstraintViolations();
List<String> errorMessages = constraintViolations.stream()
.map(constraintViolation -> {

View File

@ -16,6 +16,7 @@
package org.openmetadata.catalog.jdbi3;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.jdbi.v3.sqlobject.transaction.Transaction;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.entity.services.DashboardService;
@ -91,14 +92,24 @@ public class DashboardServiceRepository extends EntityRepository<DashboardServic
}
@Override
public void store(DashboardService entity, boolean update) throws IOException {
dao.dashboardServiceDAO().insert(entity);
public void store(DashboardService service, boolean update) throws IOException {
if (update) {
dao.dashboardServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
} else {
dao.dashboardServiceDAO().insert(service);
}
}
@Override
public void storeRelationships(DashboardService entity) throws IOException {
}
@Override
public EntityUpdater getUpdater(DashboardService original, DashboardService updated, boolean patchOperation)
throws IOException {
return new DashboardServiceUpdater(original, updated, patchOperation);
}
public static class DashboardServiceEntityInterface implements EntityInterface<DashboardService> {
private final DashboardService entity;
@ -193,4 +204,26 @@ public class DashboardServiceRepository extends EntityRepository<DashboardServic
@Override
public void setTags(List<TagLabel> tags) { }
}
public class DashboardServiceUpdater extends EntityUpdater {
public DashboardServiceUpdater(DashboardService original, DashboardService updated, boolean patchOperation) {
super(original, updated, patchOperation);
}
@Override
public void entitySpecificUpdate() throws IOException {
updateDashboardUrl();
updateIngestionSchedule();
}
private void updateDashboardUrl() throws JsonProcessingException {
recordChange("dashboardUrl", original.getEntity().getDashboardUrl(), updated.getEntity().getDashboardUrl());
}
private void updateIngestionSchedule() throws JsonProcessingException {
Schedule origSchedule = original.getEntity().getIngestionSchedule();
Schedule updatedSchedule = updated.getEntity().getIngestionSchedule();
recordChange("ingestionSchedule", origSchedule, updatedSchedule);
}
}
}

View File

@ -16,6 +16,7 @@
package org.openmetadata.catalog.jdbi3;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.jdbi.v3.sqlobject.transaction.Transaction;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.entity.services.DatabaseService;
@ -92,15 +93,23 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
}
@Override
public void store(DatabaseService entity, boolean update) throws IOException {
dao.dbServiceDAO().insert(entity);
// TODO other cleanup
public void store(DatabaseService service, boolean update) throws IOException {
if (update) {
dao.dbServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
} else {
dao.dbServiceDAO().insert(service);
}
}
@Override
public void storeRelationships(DatabaseService entity) throws IOException {
}
@Override
public EntityUpdater getUpdater(DatabaseService original, DatabaseService updated, boolean patchOperation) throws IOException {
return new DatabaseServiceUpdater(original, updated, patchOperation);
}
public static class DatabaseServiceEntityInterface implements EntityInterface<DatabaseService> {
private final DatabaseService entity;
@ -193,4 +202,28 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
@Override
public void setTags(List<TagLabel> tags) { }
}
public class DatabaseServiceUpdater extends EntityUpdater {
public DatabaseServiceUpdater(DatabaseService original, DatabaseService updated, boolean patchOperation) {
super(original, updated, patchOperation);
}
@Override
public void entitySpecificUpdate() throws IOException {
updateJdbc();
updateIngestionSchedule();
}
private void updateJdbc() throws JsonProcessingException {
JdbcInfo origJdbc = original.getEntity().getJdbc();
JdbcInfo updatedJdbc = updated.getEntity().getJdbc();
recordChange("jdbc", origJdbc, updatedJdbc);
}
private void updateIngestionSchedule() throws JsonProcessingException {
Schedule origSchedule = original.getEntity().getIngestionSchedule();
Schedule updatedSchedule = updated.getEntity().getIngestionSchedule();
recordChange("ingestionSchedule", origSchedule, updatedSchedule);
}
}
}

View File

@ -381,7 +381,7 @@ public abstract class EntityRepository<T> {
}
}
protected void updateTags(String fqn, String fieldName, List<TagLabel> origTags, List<TagLabel> updatedTags)
protected final void updateTags(String fqn, String fieldName, List<TagLabel> origTags, List<TagLabel> updatedTags)
throws IOException {
// Remove current entity tags in the database. It will be added back later from the merged tag list.
origTags = Optional.ofNullable(origTags).orElse(Collections.emptyList());

View File

@ -16,6 +16,7 @@
package org.openmetadata.catalog.jdbi3;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.jdbi.v3.sqlobject.transaction.Transaction;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.entity.services.MessagingService;
@ -30,7 +31,6 @@ import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.EntityUtil.Fields;
import org.openmetadata.catalog.util.JsonUtils;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.net.URI;
import java.text.ParseException;
@ -49,19 +49,6 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
this.dao = dao;
}
@Transaction
public MessagingService update(UriInfo uriInfo, UUID id, String description, List<String> brokers, URI schemaRegistry,
Schedule ingestionSchedule)
throws IOException {
EntityUtil.validateIngestionSchedule(ingestionSchedule);
MessagingService dbService = dao.messagingServiceDAO().findEntityById(id);
// Update fields
dbService.withDescription(description).withIngestionSchedule(ingestionSchedule)
.withSchemaRegistry(schemaRegistry).withBrokers(brokers);
dao.messagingServiceDAO().update(id, JsonUtils.pojoToJson(dbService));
return withHref(uriInfo, dbService);
}
@Transaction
public void delete(UUID id) {
if (dao.messagingServiceDAO().delete(id) <= 0) {
@ -78,7 +65,7 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
@Override
public void restorePatchAttributes(MessagingService original, MessagingService updated) throws IOException,
ParseException {
// Not implemented
}
@Override
@ -92,14 +79,22 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
}
@Override
public void store(MessagingService entity, boolean update) throws IOException {
dao.messagingServiceDAO().insert(entity);
// TODO Other cleanup
public void store(MessagingService service, boolean update) throws IOException {
if (update) {
dao.messagingServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
} else {
dao.messagingServiceDAO().insert(service);
}
}
@Override
public void storeRelationships(MessagingService entity) throws IOException { }
@Override
public EntityUpdater getUpdater(MessagingService original, MessagingService updated, boolean patchOperation) throws IOException {
return new MessagingServiceUpdater(original, updated, patchOperation);
}
public static class MessagingServiceEntityInterface implements EntityInterface<MessagingService> {
private final MessagingService entity;
@ -194,4 +189,26 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
@Override
public void setTags(List<TagLabel> tags) { }
}
public class MessagingServiceUpdater extends EntityUpdater {
public MessagingServiceUpdater(MessagingService original, MessagingService updated, boolean patchOperation) {
super(original, updated, patchOperation);
}
@Override
public void entitySpecificUpdate() throws IOException {
updateSchemaRegistry();
updateIngestionSchedule();
}
private void updateSchemaRegistry() throws JsonProcessingException {
recordChange("schemaRegistry", original.getEntity().getSchemaRegistry(), updated.getEntity().getSchemaRegistry());
}
private void updateIngestionSchedule() throws JsonProcessingException {
Schedule origSchedule = original.getEntity().getIngestionSchedule();
Schedule updatedSchedule = updated.getEntity().getIngestionSchedule();
recordChange("ingestionSchedule", origSchedule, updatedSchedule);
}
}
}

View File

@ -329,5 +329,4 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
recordListChange("tasks", origTasks, updatedTasks, added, deleted, EntityUtil.taskMatch);
}
}
}

View File

@ -16,6 +16,7 @@
package org.openmetadata.catalog.jdbi3;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.jdbi.v3.sqlobject.transaction.Transaction;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.entity.services.PipelineService;
@ -93,8 +94,12 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
}
@Override
public void store(PipelineService entity, boolean update) throws IOException {
dao.pipelineServiceDAO().insert(entity);
public void store(PipelineService service, boolean update) throws IOException {
if (update) {
dao.pipelineServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
} else {
dao.pipelineServiceDAO().insert(service);
}
}
@Override
@ -102,6 +107,11 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
}
@Override
public EntityUpdater getUpdater(PipelineService original, PipelineService updated, boolean patchOperation) throws IOException {
return new PipelineServiceUpdater(original, updated, patchOperation);
}
public static class PipelineServiceEntityInterface implements EntityInterface<PipelineService> {
private final PipelineService entity;
@ -196,4 +206,26 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
@Override
public void setTags(List<TagLabel> tags) { }
}
public class PipelineServiceUpdater extends EntityUpdater {
public PipelineServiceUpdater(PipelineService original, PipelineService updated, boolean patchOperation) {
super(original, updated, patchOperation);
}
@Override
public void entitySpecificUpdate() throws IOException {
updatePipelineUrl();
updateIngestionSchedule();
}
private void updatePipelineUrl() throws JsonProcessingException {
recordChange("pipelineUrl", original.getEntity().getPipelineUrl(), updated.getEntity().getPipelineUrl());
}
private void updateIngestionSchedule() throws JsonProcessingException {
Schedule origSchedule = original.getEntity().getIngestionSchedule();
Schedule updatedSchedule = updated.getEntity().getIngestionSchedule();
recordChange("ingestionSchedule", origSchedule, updatedSchedule);
}
}
}

View File

@ -85,9 +85,12 @@ public class StorageServiceRepository extends EntityRepository<StorageService> {
@Override
public void store(StorageService entity, boolean update) throws IOException {
dao.storageServiceDAO().insert(entity);
// TODO other cleanup
public void store(StorageService service, boolean update) throws IOException {
if (update) {
dao.storageServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
} else {
dao.storageServiceDAO().insert(service);
}
}
@Override

View File

@ -24,7 +24,6 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.openmetadata.catalog.api.services.CreateDashboardService;
import org.openmetadata.catalog.api.services.UpdateDashboardService;
import org.openmetadata.catalog.entity.services.DashboardService;
import org.openmetadata.catalog.jdbi3.CollectionDAO;
import org.openmetadata.catalog.jdbi3.DashboardServiceRepository;
@ -32,6 +31,7 @@ import org.openmetadata.catalog.resources.Collection;
import org.openmetadata.catalog.security.CatalogAuthorizer;
import org.openmetadata.catalog.security.SecurityUtil;
import org.openmetadata.catalog.util.RestUtil;
import org.openmetadata.catalog.util.RestUtil.PutResponse;
import org.openmetadata.catalog.util.ResultList;
import javax.validation.Valid;
@ -160,22 +160,12 @@ public class DashboardServiceResource {
@Context SecurityContext securityContext,
@Valid CreateDashboardService create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
DashboardService service = new DashboardService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType())
.withDashboardUrl(create.getDashboardUrl())
.withUsername(create.getUsername())
.withPassword(create.getPassword())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
DashboardService service = getService(create, securityContext);
dao.create(uriInfo, service);
return Response.created(service.getHref()).entity(service).build();
}
@PUT
@Path("/{id}")
@Operation(summary = "Update a Dashboard service", tags = "services",
description = "Update an existing dashboard service identified by `id`.",
responses = {
@ -186,13 +176,11 @@ public class DashboardServiceResource {
})
public Response update(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "Id of the dashboard service", schema = @Schema(type = "string"))
@PathParam("id") String id,
@Valid UpdateDashboardService update) throws IOException {
@Valid CreateDashboardService update) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
DashboardService service = dao.update(uriInfo, UUID.fromString(id), update.getDescription(),
update.getDashboardUrl(), update.getUsername(), update.getPassword(), update.getIngestionSchedule());
return Response.ok(service).build();
DashboardService service = getService(update, securityContext);
PutResponse<DashboardService> response = dao.createOrUpdate(uriInfo, service);
return response.toResponse();
}
@DELETE
@ -213,4 +201,15 @@ public class DashboardServiceResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private DashboardService getService(CreateDashboardService create, SecurityContext securityContext) {
return new DashboardService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType())
.withDashboardUrl(create.getDashboardUrl())
.withUsername(create.getUsername())
.withPassword(create.getPassword())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -24,7 +24,6 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.openmetadata.catalog.api.services.CreateDatabaseService;
import org.openmetadata.catalog.api.services.UpdateDatabaseService;
import org.openmetadata.catalog.entity.services.DatabaseService;
import org.openmetadata.catalog.jdbi3.CollectionDAO;
import org.openmetadata.catalog.jdbi3.DatabaseServiceRepository;
@ -32,6 +31,7 @@ import org.openmetadata.catalog.resources.Collection;
import org.openmetadata.catalog.security.CatalogAuthorizer;
import org.openmetadata.catalog.security.SecurityUtil;
import org.openmetadata.catalog.util.RestUtil;
import org.openmetadata.catalog.util.RestUtil.PutResponse;
import org.openmetadata.catalog.util.ResultList;
import javax.validation.Valid;
@ -160,19 +160,12 @@ public class DatabaseServiceResource {
@Context SecurityContext securityContext,
@Valid CreateDatabaseService create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
DatabaseService databaseService = new DatabaseService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType()).withJdbc(create.getJdbc())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
dao.create(uriInfo, databaseService);
return Response.created(databaseService.getHref()).entity(databaseService).build();
DatabaseService service = getService(create, securityContext);
dao.create(uriInfo, service);
return Response.created(service.getHref()).entity(service).build();
}
@PUT
@Path("/{id}")
@Operation(summary = "Update a database service", tags = "services",
description = "Update an existing database service identified by `id`.",
responses = {
@ -183,14 +176,11 @@ public class DatabaseServiceResource {
})
public Response update(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "Id of the database service", schema = @Schema(type = "string"))
@PathParam("id") String id,
@Valid UpdateDatabaseService update) throws IOException {
@Valid CreateDatabaseService update) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
DatabaseService databaseService =
dao.update(uriInfo, UUID.fromString(id), update.getDescription(), update.getJdbc(),
update.getIngestionSchedule());
return Response.ok(databaseService).build();
DatabaseService service = getService(update, securityContext);
PutResponse<DatabaseService> response = dao.createOrUpdate(uriInfo, service);
return response.toResponse();
}
@DELETE
@ -211,4 +201,13 @@ public class DatabaseServiceResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private DatabaseService getService(CreateDatabaseService create, SecurityContext securityContext) {
return new DatabaseService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType()).withJdbc(create.getJdbc())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -24,13 +24,13 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.openmetadata.catalog.api.services.CreateMessagingService;
import org.openmetadata.catalog.api.services.UpdateMessagingService;
import org.openmetadata.catalog.entity.services.MessagingService;
import org.openmetadata.catalog.jdbi3.CollectionDAO;
import org.openmetadata.catalog.jdbi3.MessagingServiceRepository;
import org.openmetadata.catalog.resources.Collection;
import org.openmetadata.catalog.security.CatalogAuthorizer;
import org.openmetadata.catalog.security.SecurityUtil;
import org.openmetadata.catalog.util.RestUtil.PutResponse;
import org.openmetadata.catalog.util.ResultList;
import javax.validation.Valid;
@ -106,7 +106,9 @@ public class MessagingServiceResource {
public MessagingService get(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@PathParam("id") String id) throws IOException, ParseException {
return dao.get(uriInfo, id, null);
MessagingService service = dao.get(uriInfo, id, null);
System.out.println("Ingestion schedule in request " + service.getIngestionSchedule());
return service;
}
@GET
@ -138,23 +140,14 @@ public class MessagingServiceResource {
@Context SecurityContext securityContext,
@Valid CreateMessagingService create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
MessagingService service = new MessagingService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType())
.withBrokers(create.getBrokers())
.withSchemaRegistry(create.getSchemaRegistry())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
MessagingService service = getService(create, securityContext);
dao.create(uriInfo, service);
return Response.created(service.getHref()).entity(service).build();
}
@PUT
@Path("/{id}")
@Operation(summary = "Update a messaging service", tags = "services",
description = "Update an existing messaging service identified by `id`.",
description = "Create a new messaging service or Update an existing messaging service identified by `id`.",
responses = {
@ApiResponse(responseCode = "200", description = "Messaging service instance",
content = @Content(mediaType = "application/json",
@ -165,11 +158,11 @@ public class MessagingServiceResource {
@Context SecurityContext securityContext,
@Parameter(description = "Id of the messaging service", schema = @Schema(type = "string"))
@PathParam("id") String id,
@Valid UpdateMessagingService update) throws IOException {
@Valid CreateMessagingService update) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
MessagingService service = dao.update(uriInfo, UUID.fromString(id), update.getDescription(),
update.getBrokers(), update.getSchemaRegistry(), update.getIngestionSchedule());
return Response.ok(service).build();
MessagingService service = getService(update, securityContext);
PutResponse<MessagingService> response = dao.createOrUpdate(uriInfo, service);
return response.toResponse();
}
@DELETE
@ -190,4 +183,16 @@ public class MessagingServiceResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private MessagingService getService(CreateMessagingService create, SecurityContext securityContext) {
System.out.println("Ingestion schedule in request " + create.getIngestionSchedule());
return new MessagingService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType())
.withBrokers(create.getBrokers())
.withSchemaRegistry(create.getSchemaRegistry())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -24,7 +24,6 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.openmetadata.catalog.api.services.CreatePipelineService;
import org.openmetadata.catalog.api.services.UpdatePipelineService;
import org.openmetadata.catalog.entity.services.PipelineService;
import org.openmetadata.catalog.jdbi3.CollectionDAO;
import org.openmetadata.catalog.jdbi3.PipelineServiceRepository;
@ -33,6 +32,7 @@ import org.openmetadata.catalog.security.CatalogAuthorizer;
import org.openmetadata.catalog.security.SecurityUtil;
import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.util.RestUtil;
import org.openmetadata.catalog.util.RestUtil.PutResponse;
import org.openmetadata.catalog.util.ResultList;
import javax.validation.Valid;
@ -143,21 +143,14 @@ public class PipelineServiceResource {
@Context SecurityContext securityContext,
@Valid CreatePipelineService create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
PipelineService service = new PipelineService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType())
.withPipelineUrl(create.getPipelineUrl())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
PipelineService service = getService(create, securityContext);
dao.create(uriInfo, service);
return Response.created(service.getHref()).entity(service).build();
}
@PUT
@Path("/{id}")
@Operation(summary = "Update a pipeline service", tags = "services",
description = "Update an existing pipeline service identified by `id`.",
description = "Create a new pipeline service or update an existing pipeline service identified by `id`.",
responses = {
@ApiResponse(responseCode = "200", description = "Pipeline service instance",
content = @Content(mediaType = "application/json",
@ -166,13 +159,11 @@ public class PipelineServiceResource {
})
public Response update(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "Id of the pipeline service", schema = @Schema(type = "string"))
@PathParam("id") String id,
@Valid UpdatePipelineService update) throws IOException {
@Valid CreatePipelineService update) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
PipelineService service = dao.update(uriInfo, UUID.fromString(id), update.getDescription(), update.getPipelineUrl(),
update.getIngestionSchedule());
return Response.ok(service).build();
PipelineService service = getService(update, securityContext);
PutResponse<PipelineService> response = dao.createOrUpdate(uriInfo, service);
return response.toResponse();
}
@DELETE
@ -193,4 +184,13 @@ public class PipelineServiceResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private PipelineService getService(CreatePipelineService create, SecurityContext securityContext) {
return new PipelineService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType())
.withPipelineUrl(create.getPipelineUrl())
.withIngestionSchedule(create.getIngestionSchedule())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -24,13 +24,13 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.openmetadata.catalog.api.services.CreateStorageService;
import org.openmetadata.catalog.api.services.UpdateStorageService;
import org.openmetadata.catalog.entity.services.StorageService;
import org.openmetadata.catalog.jdbi3.CollectionDAO;
import org.openmetadata.catalog.jdbi3.StorageServiceRepository;
import org.openmetadata.catalog.resources.Collection;
import org.openmetadata.catalog.security.CatalogAuthorizer;
import org.openmetadata.catalog.security.SecurityUtil;
import org.openmetadata.catalog.util.RestUtil.PutResponse;
import org.openmetadata.catalog.util.ResultList;
import javax.validation.Valid;
@ -137,17 +137,12 @@ public class StorageServiceResource {
@Context SecurityContext securityContext,
@Valid CreateStorageService create) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
StorageService databaseService = new StorageService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType()).withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
StorageService databaseService = getService(create, securityContext);
dao.create(uriInfo, databaseService);
return Response.created(databaseService.getHref()).entity(databaseService).build();
}
@PUT
@Path("/{id}")
@Operation(summary = "Update a storage service", tags = "services",
description = "Update an existing storage service identified by `id`.",
responses = {
@ -158,12 +153,11 @@ public class StorageServiceResource {
})
public Response update(@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "Id of the storage service", schema = @Schema(type = "string"))
@PathParam("id") String id,
@Valid UpdateStorageService update) throws IOException {
@Valid CreateStorageService update) throws IOException, ParseException {
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
StorageService databaseService = dao.update(uriInfo, UUID.fromString(id), update.getDescription());
return Response.ok(databaseService).build();
StorageService databaseService = getService(update, securityContext);
PutResponse<StorageService> response = dao.createOrUpdate(uriInfo, databaseService);
return response.toResponse();
}
@DELETE
@ -184,4 +178,11 @@ public class StorageServiceResource {
dao.delete(UUID.fromString(id));
return Response.ok().build();
}
private StorageService getService(CreateStorageService create, SecurityContext securityContext) {
return new StorageService().withId(UUID.randomUUID())
.withName(create.getName()).withDescription(create.getDescription())
.withServiceType(create.getServiceType()).withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(new Date());
}
}

View File

@ -1,31 +0,0 @@
{
"$id": "https://open-metadata.org/schema/api/services/updateDashboardService.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Update Dashboard service entity request",
"description": "Update Dashboard service entity request",
"type": "object",
"properties" : {
"description": {
"description": "Description of Dashboard service entity.",
"type": "string"
},
"dashboardUrl": {
"description": "Dashboard Service URL",
"type": "string",
"format": "uri"
},
"username" : {
"description": "Username to log-into Dashboard Service",
"type": "string"
},
"password" : {
"description": "Password to log-into Dashboard Service",
"type": "string"
},
"ingestionSchedule" : {
"description": "Schedule for running metadata ingestion jobs",
"$ref" : "../../type/schedule.json"
}
}
}

View File

@ -1,21 +0,0 @@
{
"$id": "https://open-metadata.org/schema/api/services/updateDatabaseService.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Update Database service entity request",
"description": "Update Database service entity request",
"type": "object",
"properties" : {
"description": {
"description": "Description of Database service entity.",
"type": "string"
},
"jdbc": {
"$ref" : "../../type/jdbcConnection.json#/definitions/jdbcInfo"
},
"ingestionSchedule" : {
"description": "Schedule for running metadata ingestion jobs",
"$ref" : "../../type/schedule.json"
}
}
}

View File

@ -1,26 +0,0 @@
{
"$id": "https://open-metadata.org/schema/api/services/updateMessagingService.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Update Messaging service entity request",
"description": "Update Messaging service entity request",
"type": "object",
"properties" : {
"description": {
"description": "Description of Messaging service entity.",
"type": "string"
},
"brokers": {
"$ref" : "../../entity/services/messagingService.json#/definitions/brokers"
},
"schemaRegistry" : {
"description": "Schema registry URL.",
"type": "string",
"format": "uri"
},
"ingestionSchedule" : {
"description": "Schedule for running metadata ingestion jobs",
"$ref" : "../../type/schedule.json"
}
}
}

View File

@ -1,23 +0,0 @@
{
"$id": "https://open-metadata.org/schema/api/services/updatePipelineService.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Update pipeline service entity request",
"description": "Update pipeline service entity request",
"type": "object",
"properties" : {
"description": {
"description": "Description of Pipeline service entity.",
"type": "string"
},
"pipelineUrl" : {
"description": "Pipeline Service UI URL.",
"type": "string",
"format": "uri"
},
"ingestionSchedule" : {
"description": "Schedule for running metadata ingestion jobs",
"$ref" : "../../type/schedule.json"
}
}
}

View File

@ -1,14 +0,0 @@
{
"$id": "https://open-metadata.org/schema/api/services/updateStorageService.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Update Storage service entity request",
"description": "Update Storage service entity request",
"type": "object",
"properties" : {
"description": {
"description": "Description of Storage service entity.",
"type": "string"
}
}
}

View File

@ -23,11 +23,9 @@ import org.openmetadata.catalog.CatalogApplicationTest;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.services.CreateDashboardService;
import org.openmetadata.catalog.api.services.CreateDashboardService.DashboardServiceType;
import org.openmetadata.catalog.api.services.UpdateDashboardService;
import org.openmetadata.catalog.entity.services.DashboardService;
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
import org.openmetadata.catalog.type.Schedule;
import org.openmetadata.catalog.util.RestUtil;
import org.openmetadata.catalog.util.TestUtils;
import javax.ws.rs.client.WebTarget;
@ -174,34 +172,24 @@ public class DashboardServiceResourceTest extends CatalogApplicationTest {
"be more than 60 minutes");
}
@Test
public void put_updateNonExistentService_404() {
// Update dashboard description and ingestion service that are null
UpdateDashboardService update = new UpdateDashboardService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
-> updateDashboardService(TestUtils.NON_EXISTENT_ENTITY.toString(), update, OK, adminAuthHeaders()));
TestUtils.assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("DashboardService",
TestUtils.NON_EXISTENT_ENTITY));
}
@Test
public void put_updateService_as_admin_2xx(TestInfo test) throws HttpResponseException, URISyntaxException {
DashboardService dbService = createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null),
adminAuthHeaders());
String id = dbService.getId().toString();
// Update dashboard description and ingestion service that are null
UpdateDashboardService update = new UpdateDashboardService().withDescription("description1")
CreateDashboardService update = create(test).withDescription("description1")
.withDashboardUrl(new URI("http://localhost:8080")).withUsername("user").withPassword("password");
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
// Update ingestion schedule
Schedule schedule = new Schedule().withStartDate(new Date()).withRepeatFrequency("P1D");
update.withIngestionSchedule(schedule);
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
// Update description and ingestion schedule again
update.withDescription("description1").withIngestionSchedule(schedule.withRepeatFrequency("PT1H"));
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
}
@Test
@ -209,14 +197,10 @@ public class DashboardServiceResourceTest extends CatalogApplicationTest {
Map<String, String> authHeaders = adminAuthHeaders();
DashboardService dbService = createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null),
authHeaders);
String id = dbService.getId().toString();
RestUtil.DATE_TIME_FORMAT.format(new Date());
// Update dashboard description and ingestion service that are null
UpdateDashboardService update = new UpdateDashboardService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
updateAndCheckService(id, update, OK, authHeaders("test@open-metadata.org")));
updateAndCheckService(create(test), OK, authHeaders("test@open-metadata.org")));
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " +
"is not admin");
}
@ -354,10 +338,10 @@ public class DashboardServiceResourceTest extends CatalogApplicationTest {
.withIngestionSchedule(new Schedule().withStartDate(new Date()).withRepeatFrequency("P1D"));
}
public static void updateAndCheckService(String id, UpdateDashboardService update, Status status,
public static void updateAndCheckService(CreateDashboardService update, Status status,
Map<String, String> authHeaders) throws HttpResponseException {
String updatedBy = TestUtils.getPrincipal(authHeaders);
DashboardService service = updateDashboardService(id, update, status, authHeaders);
DashboardService service = updateDashboardService(update, status, authHeaders);
validateService(service, service.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
// GET the newly updated dashboard and validate
@ -369,10 +353,10 @@ public class DashboardServiceResourceTest extends CatalogApplicationTest {
validateService(getService, service.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
}
public static DashboardService updateDashboardService(String id, UpdateDashboardService updated,
public static DashboardService updateDashboardService(CreateDashboardService updated,
Status status, Map<String, String> authHeaders)
throws HttpResponseException {
return TestUtils.put(CatalogApplicationTest.getResource("services/dashboardServices/" + id), updated,
return TestUtils.put(CatalogApplicationTest.getResource("services/dashboardServices"), updated,
DashboardService.class, status, authHeaders);
}
}

View File

@ -23,12 +23,10 @@ import org.openmetadata.catalog.CatalogApplicationTest;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.services.CreateDatabaseService;
import org.openmetadata.catalog.api.services.CreateDatabaseService.DatabaseServiceType;
import org.openmetadata.catalog.type.Schedule;
import org.openmetadata.catalog.api.services.UpdateDatabaseService;
import org.openmetadata.catalog.entity.services.DatabaseService;
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
import org.openmetadata.catalog.type.JdbcInfo;
import org.openmetadata.catalog.util.RestUtil;
import org.openmetadata.catalog.type.Schedule;
import org.openmetadata.catalog.util.TestUtils;
import javax.ws.rs.client.WebTarget;
@ -167,48 +165,30 @@ public class DatabaseServiceResourceTest extends CatalogApplicationTest {
"be more than 60 minutes");
}
@Test
public void put_updateNonExistentService_404() {
// Update database description and ingestion service that are null
UpdateDatabaseService update = new UpdateDatabaseService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
-> updateDatabaseService(TestUtils.NON_EXISTENT_ENTITY.toString(), update, OK, adminAuthHeaders()));
TestUtils.assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("DatabaseService",
TestUtils.NON_EXISTENT_ENTITY));
}
@Test
public void put_updateDatabaseService_as_admin_2xx(TestInfo test) throws HttpResponseException {
DatabaseService dbService = createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null),
adminAuthHeaders());
String id = dbService.getId().toString();
createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null), adminAuthHeaders());
// Update database description and ingestion service that are null
UpdateDatabaseService update = new UpdateDatabaseService().withDescription("description1");
updateAndCheckService(id, update, OK, adminAuthHeaders());
CreateDatabaseService update = create(test).withDescription("description1");
updateAndCheckService(update, OK, adminAuthHeaders());
// Update ingestion schedule
Schedule schedule = new Schedule().withStartDate(new Date()).withRepeatFrequency("P1D");
update.withIngestionSchedule(schedule);
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
// Update description and ingestion schedule again
update.withDescription("description1").withIngestionSchedule(schedule.withRepeatFrequency("PT1H"));
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
}
@Test
public void put_update_as_non_admin_401(TestInfo test) throws HttpResponseException {
Map<String, String> authHeaders = adminAuthHeaders();
DatabaseService dbService = createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null),
authHeaders);
String id = dbService.getId().toString();
RestUtil.DATE_TIME_FORMAT.format(new Date());
// Update database description and ingestion service that are null
UpdateDatabaseService update = new UpdateDatabaseService().withDescription("description1");
createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null), authHeaders);
// Update as non admin should be forbidden
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
updateAndCheckService(id, update, OK, authHeaders("test@open-metadata.org")));
updateAndCheckService(create(test), OK, authHeaders("test@open-metadata.org")));
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " +
"is not admin");
}
@ -348,10 +328,10 @@ public class DatabaseServiceResourceTest extends CatalogApplicationTest {
.withJdbc(TestUtils.JDBC_INFO);
}
public static void updateAndCheckService(String id, UpdateDatabaseService update, Status status,
public static void updateAndCheckService(CreateDatabaseService update, Status status,
Map<String, String> authHeaders) throws HttpResponseException {
String updatedBy = TestUtils.getPrincipal(authHeaders);
DatabaseService service = updateDatabaseService(id, update, status, authHeaders);
DatabaseService service = updateDatabaseService(update, status, authHeaders);
validateService(service, service.getName(), update.getDescription(), service.getJdbc(),
update.getIngestionSchedule(), updatedBy);
@ -366,10 +346,10 @@ public class DatabaseServiceResourceTest extends CatalogApplicationTest {
update.getIngestionSchedule(), updatedBy);
}
public static DatabaseService updateDatabaseService(String id, UpdateDatabaseService updated,
public static DatabaseService updateDatabaseService(CreateDatabaseService updated,
Status status, Map<String, String> authHeaders)
throws HttpResponseException {
return TestUtils.put(CatalogApplicationTest.getResource("services/databaseServices/" + id), updated,
return TestUtils.put(CatalogApplicationTest.getResource("services/databaseServices"), updated,
DatabaseService.class, status, authHeaders);
}
}

View File

@ -24,7 +24,6 @@ import org.openmetadata.catalog.CatalogApplicationTest;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.services.CreateMessagingService;
import org.openmetadata.catalog.api.services.CreateMessagingService.MessagingServiceType;
import org.openmetadata.catalog.api.services.UpdateMessagingService;
import org.openmetadata.catalog.entity.services.MessagingService;
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
import org.openmetadata.catalog.type.Schedule;
@ -186,37 +185,27 @@ public class MessagingServiceResourceTest extends CatalogApplicationTest {
"be more than 60 minutes");
}
@Test
public void put_updateNonExistentService_404() {
// Update messaging description and ingestion service that are null
UpdateMessagingService update = new UpdateMessagingService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
-> updateMessagingService(TestUtils.NON_EXISTENT_ENTITY.toString(), update, OK, adminAuthHeaders()));
TestUtils.assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("MessagingService",
TestUtils.NON_EXISTENT_ENTITY));
}
@Test
public void put_updateService_as_admin_2xx(TestInfo test) throws HttpResponseException, URISyntaxException {
MessagingService dbService = createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null)
.withBrokers(KAFKA_BROKERS).withSchemaRegistry(SCHEMA_REGISTRY_URL), adminAuthHeaders());
String id = dbService.getId().toString();
// Update messaging description and ingestion service that are null
UpdateMessagingService update = new UpdateMessagingService().withDescription("description1");
updateAndCheckService(id, update, OK, adminAuthHeaders());
CreateMessagingService update = create(test).withDescription("description1").withIngestionSchedule(null);
updateAndCheckService(update, OK, adminAuthHeaders());
// Update ingestion schedule
Schedule schedule = new Schedule().withStartDate(new Date()).withRepeatFrequency("P1D");
update.withIngestionSchedule(schedule);
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
// Update description and ingestion schedule again
update.withDescription("description1").withIngestionSchedule(schedule.withRepeatFrequency("PT1H"));
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
// update broker list and schema registry
update.withBrokers(List.of("localhost:0")).withSchemaRegistry(new URI("http://localhost:9000"));
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
MessagingService updatedService = getService(dbService.getId(), adminAuthHeaders());
validateMessagingServiceConfig(updatedService, List.of("localhost:0"), new URI("http://localhost:9000"));
}
@ -229,11 +218,9 @@ public class MessagingServiceResourceTest extends CatalogApplicationTest {
String id = dbService.getId().toString();
RestUtil.DATE_TIME_FORMAT.format(new Date());
// Update messaging description and ingestion service that are null
UpdateMessagingService update = new UpdateMessagingService().withDescription("description1");
// Update messaging description as non admin and expect exception
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
updateAndCheckService(id, update, OK, authHeaders("test@open-metadata.org")));
updateAndCheckService(create(test), OK, authHeaders("test@open-metadata.org")));
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " +
"is not admin");
}
@ -370,25 +357,25 @@ public class MessagingServiceResourceTest extends CatalogApplicationTest {
.withIngestionSchedule(new Schedule().withStartDate(new Date()).withRepeatFrequency("P1D"));
}
public static void updateAndCheckService(String id, UpdateMessagingService update, Status status,
public static void updateAndCheckService(CreateMessagingService update, Status status,
Map<String, String> authHeaders) throws HttpResponseException {
String updatedBy = TestUtils.getPrincipal(authHeaders);
MessagingService service = updateMessagingService(id, update, status, authHeaders);
validateService(service, service.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
MessagingService service = updateMessagingService(update, status, authHeaders);
validateService(service, update.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
// GET the newly updated messaging and validate
MessagingService getService = getService(service.getId(), authHeaders);
validateService(getService, service.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
validateService(getService, update.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
// GET the newly updated messaging by name and validate
getService = getServiceByName(service.getName(), null, authHeaders);
validateService(getService, service.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
validateService(getService, update.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
}
public static MessagingService updateMessagingService(String id, UpdateMessagingService updated,
public static MessagingService updateMessagingService(CreateMessagingService updated,
Status status, Map<String, String> authHeaders)
throws HttpResponseException {
return TestUtils.put(CatalogApplicationTest.getResource("services/messagingServices/" + id), updated,
return TestUtils.put(CatalogApplicationTest.getResource("services/messagingServices"), updated,
MessagingService.class, status, authHeaders);
}

View File

@ -23,7 +23,6 @@ import org.junit.jupiter.api.TestInfo;
import org.openmetadata.catalog.CatalogApplicationTest;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.services.CreatePipelineService;
import org.openmetadata.catalog.api.services.UpdatePipelineService;
import org.openmetadata.catalog.entity.services.PipelineService;
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
import org.openmetadata.catalog.type.Schedule;
@ -182,37 +181,27 @@ public class PipelineServiceResourceTest extends CatalogApplicationTest {
"be more than 60 minutes");
}
@Test
public void put_updateNonExistentService_404() {
// Update pipeline description and ingestion service that are null
UpdatePipelineService update = new UpdatePipelineService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
-> updatePipelineService(TestUtils.NON_EXISTENT_ENTITY.toString(), update, OK, adminAuthHeaders()));
TestUtils.assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("PipelineService",
TestUtils.NON_EXISTENT_ENTITY));
}
@Test
public void put_updateService_as_admin_2xx(TestInfo test) throws HttpResponseException, URISyntaxException {
PipelineService dbService = createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null)
.withPipelineUrl(PIPELINE_SERVICE_URL), adminAuthHeaders());
String id = dbService.getId().toString();
// Update pipeline description and ingestion service that are null
UpdatePipelineService update = new UpdatePipelineService().withDescription("description1");
updateAndCheckService(id, update, OK, adminAuthHeaders());
CreatePipelineService update = create(test).withDescription("description1");
updateAndCheckService(update, OK, adminAuthHeaders());
// Update ingestion schedule
Schedule schedule = new Schedule().withStartDate(new Date()).withRepeatFrequency("P1D");
update.withIngestionSchedule(schedule);
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
// Update description and ingestion schedule again
update.withDescription("description1").withIngestionSchedule(schedule.withRepeatFrequency("PT1H"));
updateAndCheckService(id, update, OK, adminAuthHeaders());
// Update ingestion schedule again
update.withIngestionSchedule(schedule.withRepeatFrequency("PT1H"));
updateAndCheckService(update, OK, adminAuthHeaders());
// update broker list and schema registry
update.withPipelineUrl(new URI("http://localhost:9000"));
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
PipelineService updatedService = getService(dbService.getId(), adminAuthHeaders());
validatePipelineServiceConfig(updatedService, List.of("localhost:0"), new URI("http://localhost:9000"));
}
@ -223,14 +212,10 @@ public class PipelineServiceResourceTest extends CatalogApplicationTest {
PipelineService pipelineService = createAndCheckService(create(test).withDescription(null)
.withIngestionSchedule(null),
authHeaders);
String id = pipelineService.getId().toString();
RestUtil.DATE_TIME_FORMAT.format(new Date());
// Update pipeline description and ingestion service that are null
UpdatePipelineService update = new UpdatePipelineService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
updateAndCheckService(id, update, OK, authHeaders("test@open-metadata.org")));
updateAndCheckService(create(test), OK, authHeaders("test@open-metadata.org")));
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " +
"is not admin");
}
@ -368,10 +353,10 @@ public class PipelineServiceResourceTest extends CatalogApplicationTest {
.withIngestionSchedule(new Schedule().withStartDate(new Date()).withRepeatFrequency("P1D"));
}
public static void updateAndCheckService(String id, UpdatePipelineService update, Status status,
public static void updateAndCheckService(CreatePipelineService update, Status status,
Map<String, String> authHeaders) throws HttpResponseException {
String updatedBy = TestUtils.getPrincipal(authHeaders);
PipelineService service = updatePipelineService(id, update, status, authHeaders);
PipelineService service = updatePipelineService(update, status, authHeaders);
validateService(service, service.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
// GET the newly updated pipeline and validate
@ -383,10 +368,10 @@ public class PipelineServiceResourceTest extends CatalogApplicationTest {
validateService(getService, service.getName(), update.getDescription(), update.getIngestionSchedule(), updatedBy);
}
public static PipelineService updatePipelineService(String id, UpdatePipelineService updated,
public static PipelineService updatePipelineService(CreatePipelineService updated,
Status status, Map<String, String> authHeaders)
throws HttpResponseException {
return TestUtils.put(CatalogApplicationTest.getResource("services/pipelineServices/" + id), updated,
return TestUtils.put(CatalogApplicationTest.getResource("services/pipelineServices"), updated,
PipelineService.class, status, authHeaders);
}

View File

@ -6,7 +6,6 @@ import org.junit.jupiter.api.TestInfo;
import org.openmetadata.catalog.CatalogApplicationTest;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.services.CreateStorageService;
import org.openmetadata.catalog.api.services.UpdateStorageService;
import org.openmetadata.catalog.entity.services.StorageService;
import org.openmetadata.catalog.type.StorageServiceType;
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
@ -77,42 +76,28 @@ public class StorageServiceResourceTest extends CatalogApplicationTest {
"Principal: CatalogPrincipal{name='test'} is not admin");
}
@Test
public void put_updateNonExistentService_404() {
// Update storage description and ingestion service that are null
UpdateStorageService update = new UpdateStorageService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
-> updateStorageService(TestUtils.NON_EXISTENT_ENTITY.toString(), update, OK, adminAuthHeaders()));
TestUtils.assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("StorageService",
TestUtils.NON_EXISTENT_ENTITY));
}
@Test
public void put_updateStorageService_as_admin_2xx(TestInfo test) throws HttpResponseException {
StorageService dbService = createAndCheckService(create(test).withDescription(null), adminAuthHeaders());
String id = dbService.getId().toString();
// Update storage description and ingestion service that are null
UpdateStorageService update = new UpdateStorageService().withDescription("description1");
updateAndCheckService(id, update, OK, adminAuthHeaders());
CreateStorageService update = create(test).withDescription("description1");
updateAndCheckService(update, OK, adminAuthHeaders());
// Update description and ingestion schedule again
update.withDescription("description1");
updateAndCheckService(id, update, OK, adminAuthHeaders());
updateAndCheckService(update, OK, adminAuthHeaders());
}
@Test
public void put_update_as_non_admin_401(TestInfo test) throws HttpResponseException {
Map<String, String> authHeaders = adminAuthHeaders();
StorageService dbService = createAndCheckService(create(test).withDescription(null), authHeaders);
String id = dbService.getId().toString();
RestUtil.DATE_TIME_FORMAT.format(new Date());
// Update storage description and ingestion service that are null
UpdateStorageService update = new UpdateStorageService().withDescription("description1");
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
updateAndCheckService(id, update, OK, authHeaders("test@open-metadata.org")));
updateAndCheckService(create(test), OK, authHeaders("test@open-metadata.org")));
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " +
"is not admin");
}
@ -223,16 +208,16 @@ public class StorageServiceResourceTest extends CatalogApplicationTest {
return TestUtils.get(target, StorageService.class, authHeaders);
}
public static StorageService updateStorageService(String id, UpdateStorageService updated,
public static StorageService updateStorageService(CreateStorageService updated,
Response.Status status, Map<String, String> authHeaders)
throws HttpResponseException {
return TestUtils.put(CatalogApplicationTest.getResource("services/storageServices/" + id), updated,
return TestUtils.put(CatalogApplicationTest.getResource("services/storageServices"), updated,
StorageService.class, status, authHeaders);
}
public static void updateAndCheckService(String id, UpdateStorageService update, Response.Status status,
public static void updateAndCheckService(CreateStorageService update, Response.Status status,
Map<String, String> authHeaders) throws HttpResponseException {
StorageService service = updateStorageService(id, update, status, authHeaders);
StorageService service = updateStorageService(update, status, authHeaders);
validateService(service, service.getName(), update.getDescription());
// GET the newly updated storage and validate