modified neccesary files

This commit is contained in:
dec0deit 2021-11-01 14:46:27 +05:30
parent 9776cec660
commit 11f55cc1c2
6 changed files with 40 additions and 71 deletions

View File

@ -25,9 +25,8 @@ import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.type.Schedule;
import org.openmetadata.catalog.type.TagLabel; import org.openmetadata.catalog.type.TagLabel;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.EntityUtil.Fields; import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.JsonUtils;
import org.openmetadata.catalog.util.Utils;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -50,7 +49,7 @@ public class DashboardServiceRepository extends EntityRepository<DashboardServic
public DashboardService update(UUID id, String description, URI dashboardUrl, String username, String password, public DashboardService update(UUID id, String description, URI dashboardUrl, String username, String password,
Schedule ingestionSchedule) Schedule ingestionSchedule)
throws IOException { throws IOException {
Utils.validateIngestionSchedule(ingestionSchedule); EntityUtil.validateIngestionSchedule(ingestionSchedule);
DashboardService dashboardService = dao.dashboardServiceDAO().findEntityById(id); DashboardService dashboardService = dao.dashboardServiceDAO().findEntityById(id);
// Update fields // Update fields
dashboardService.withDescription(description).withDashboardUrl(dashboardUrl).withUsername(username) dashboardService.withDescription(description).withDashboardUrl(dashboardUrl).withUsername(username)
@ -84,7 +83,7 @@ public class DashboardServiceRepository extends EntityRepository<DashboardServic
@Override @Override
public void validate(DashboardService entity) throws IOException { public void validate(DashboardService entity) throws IOException {
Utils.validateIngestionSchedule(entity.getIngestionSchedule()); EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
} }
@Override @Override

View File

@ -26,9 +26,8 @@ import org.openmetadata.catalog.type.JdbcInfo;
import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.type.Schedule;
import org.openmetadata.catalog.type.TagLabel; import org.openmetadata.catalog.type.TagLabel;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.EntityUtil.Fields; import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.JsonUtils;
import org.openmetadata.catalog.util.Utils;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -50,7 +49,7 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
public DatabaseService update(UUID id, String description, JdbcInfo jdbc, Schedule ingestionSchedule) public DatabaseService update(UUID id, String description, JdbcInfo jdbc, Schedule ingestionSchedule)
throws IOException { throws IOException {
Utils.validateIngestionSchedule(ingestionSchedule); EntityUtil.validateIngestionSchedule(ingestionSchedule);
DatabaseService dbService = dao.dbServiceDAO().findEntityById(id); DatabaseService dbService = dao.dbServiceDAO().findEntityById(id);
// Update fields // Update fields
dbService.withDescription(description).withJdbc((jdbc)).withIngestionSchedule(ingestionSchedule); dbService.withDescription(description).withJdbc((jdbc)).withIngestionSchedule(ingestionSchedule);
@ -84,7 +83,7 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
@Override @Override
public void validate(DatabaseService entity) throws IOException { public void validate(DatabaseService entity) throws IOException {
Utils.validateIngestionSchedule(entity.getIngestionSchedule()); EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
} }
@Override @Override

View File

@ -25,9 +25,8 @@ import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.type.Schedule;
import org.openmetadata.catalog.type.TagLabel; import org.openmetadata.catalog.type.TagLabel;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.EntityUtil.Fields; import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.JsonUtils;
import org.openmetadata.catalog.util.Utils;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -50,7 +49,7 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
public MessagingService update(UUID id, String description, List<String> brokers, URI schemaRegistry, public MessagingService update(UUID id, String description, List<String> brokers, URI schemaRegistry,
Schedule ingestionSchedule) Schedule ingestionSchedule)
throws IOException { throws IOException {
Utils.validateIngestionSchedule(ingestionSchedule); EntityUtil.validateIngestionSchedule(ingestionSchedule);
MessagingService dbService = dao.messagingServiceDAO().findEntityById(id); MessagingService dbService = dao.messagingServiceDAO().findEntityById(id);
// Update fields // Update fields
dbService.withDescription(description).withIngestionSchedule(ingestionSchedule) dbService.withDescription(description).withIngestionSchedule(ingestionSchedule)
@ -85,7 +84,7 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
@Override @Override
public void validate(MessagingService entity) throws IOException { public void validate(MessagingService entity) throws IOException {
Utils.validateIngestionSchedule(entity.getIngestionSchedule()); EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
} }
@Override @Override

View File

@ -25,9 +25,8 @@ import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.type.Schedule;
import org.openmetadata.catalog.type.TagLabel; import org.openmetadata.catalog.type.TagLabel;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.EntityUtil.Fields; import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.JsonUtils;
import org.openmetadata.catalog.util.Utils;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -51,7 +50,7 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
public PipelineService update(UUID id, String description, URI url, public PipelineService update(UUID id, String description, URI url,
Schedule ingestionSchedule) Schedule ingestionSchedule)
throws IOException { throws IOException {
Utils.validateIngestionSchedule(ingestionSchedule); EntityUtil.validateIngestionSchedule(ingestionSchedule);
PipelineService pipelineService = dao.pipelineServiceDAO().findEntityById(id); PipelineService pipelineService = dao.pipelineServiceDAO().findEntityById(id);
// Update fields // Update fields
pipelineService.withDescription(description).withIngestionSchedule(ingestionSchedule) pipelineService.withDescription(description).withIngestionSchedule(ingestionSchedule)
@ -86,7 +85,7 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
@Override @Override
public void validate(PipelineService entity) throws IOException { public void validate(PipelineService entity) throws IOException {
Utils.validateIngestionSchedule(entity.getIngestionSchedule()); EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
} }
@Override @Override

View File

@ -72,6 +72,34 @@ public final class EntityUtil {
} }
/**
* Validate Ingestion Schedule
*/
public static void validateIngestionSchedule(Schedule ingestion) {
if (ingestion == null) {
return;
}
String duration = ingestion.getRepeatFrequency();
// ISO8601 duration format is P{y}Y{m}M{d}DT{h}H{m}M{s}S.
String[] splits = duration.split("T");
if (splits[0].contains("Y") || splits[0].contains("M") ||
(splits.length == 2 && splits[1].contains("S"))) {
throw new IllegalArgumentException("Ingestion repeatFrequency can only contain Days, Hours, and Minutes - " +
"example P{d}DT{h}H{m}M");
}
Period period;
try {
period = ISOPeriodFormat.standard().parsePeriod(duration);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid ingestion repeatFrequency " + duration, e);
}
if (period.toStandardMinutes().getMinutes() < 60) {
throw new IllegalArgumentException("Ingestion repeatFrequency is too short and must be more than 60 minutes");
}
}
/** /**
* Validate that JSON payload can be turned into POJO object * Validate that JSON payload can be turned into POJO object
*/ */

View File

@ -1,55 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openmetadata.catalog.util;
import org.joda.time.Period;
import org.joda.time.format.ISOPeriodFormat;
import org.openmetadata.catalog.type.Schedule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class Utils {
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
private Utils() {}
public static void validateIngestionSchedule(Schedule ingestion) {
if (ingestion == null) {
return;
}
String duration = ingestion.getRepeatFrequency();
// ISO8601 duration format is P{y}Y{m}M{d}DT{h}H{m}M{s}S.
String[] splits = duration.split("T");
if (splits[0].contains("Y") || splits[0].contains("M") ||
(splits.length == 2 && splits[1].contains("S"))) {
throw new IllegalArgumentException("Ingestion repeatFrequency can only contain Days, Hours, and Minutes - " +
"example P{d}DT{h}H{m}M");
}
Period period;
try {
period = ISOPeriodFormat.standard().parsePeriod(duration);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid ingestion repeatFrequency " + duration, e);
}
if (period.toStandardMinutes().getMinutes() < 60) {
throw new IllegalArgumentException("Ingestion repeatFrequency is too short and must be more than 60 minutes");
}
}
}