mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-23 17:30:35 +00:00
MINOR - Prepare App Instances & fix bigtable json (#15292)
* MINOR - Prepare App Exception & fix bigtable json * Do not init the app all the time and allow to fetch initialized resources * init installed apps * Add runtime props * Add runtime props * Format
This commit is contained in:
parent
ad9a6df282
commit
cc878bf94e
@ -0,0 +1,32 @@
|
|||||||
|
package org.openmetadata.service.apps;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import org.openmetadata.sdk.exception.WebServiceException;
|
||||||
|
|
||||||
|
public class AppException extends WebServiceException {
|
||||||
|
|
||||||
|
private static final String BY_NAME_MESSAGE = "Application [%s] Exception [%s] due to [%s].";
|
||||||
|
private static final String ERROR_TYPE = "PIPELINE_SERVICE_ERROR";
|
||||||
|
|
||||||
|
public AppException(String message) {
|
||||||
|
super(Response.Status.BAD_REQUEST, ERROR_TYPE, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AppException(Response.Status status, String message) {
|
||||||
|
super(status, ERROR_TYPE, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AppException byMessage(
|
||||||
|
String appName, String name, String errorMessage, Response.Status status) {
|
||||||
|
return new AppException(status, buildMessageByName(appName, name, errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AppException byMessage(String appName, String name, String errorMessage) {
|
||||||
|
return new AppException(
|
||||||
|
Response.Status.BAD_REQUEST, buildMessageByName(appName, name, errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildMessageByName(String appName, String name, String errorMessage) {
|
||||||
|
return String.format(BY_NAME_MESSAGE, appName, name, errorMessage);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package org.openmetadata.service.apps;
|
|||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashMap;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.openmetadata.schema.entity.app.App;
|
import org.openmetadata.schema.entity.app.App;
|
||||||
import org.openmetadata.service.exception.UnhandledServerException;
|
import org.openmetadata.service.exception.UnhandledServerException;
|
||||||
@ -11,6 +12,12 @@ import org.openmetadata.service.search.SearchRepository;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ApplicationHandler {
|
public class ApplicationHandler {
|
||||||
|
|
||||||
|
private static HashMap<String, Object> instances = new HashMap<>();
|
||||||
|
|
||||||
|
public static Object getAppInstance(String className) {
|
||||||
|
return instances.get(className);
|
||||||
|
}
|
||||||
|
|
||||||
private ApplicationHandler() {
|
private ApplicationHandler() {
|
||||||
/*Helper*/
|
/*Helper*/
|
||||||
}
|
}
|
||||||
@ -30,19 +37,36 @@ public class ApplicationHandler {
|
|||||||
runMethodFromApplication(app, daoCollection, searchRepository, "configure");
|
runMethodFromApplication(app, daoCollection, searchRepository, "configure");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object runAppInit(
|
||||||
|
App app, CollectionDAO daoCollection, SearchRepository searchRepository)
|
||||||
|
throws ClassNotFoundException,
|
||||||
|
NoSuchMethodException,
|
||||||
|
InvocationTargetException,
|
||||||
|
InstantiationException,
|
||||||
|
IllegalAccessException {
|
||||||
|
Class<?> clz = Class.forName(app.getClassName());
|
||||||
|
Object resource =
|
||||||
|
clz.getDeclaredConstructor(CollectionDAO.class, SearchRepository.class)
|
||||||
|
.newInstance(daoCollection, searchRepository);
|
||||||
|
|
||||||
|
// Call init Method
|
||||||
|
Method initMethod = resource.getClass().getMethod("init", App.class);
|
||||||
|
initMethod.invoke(resource, app);
|
||||||
|
|
||||||
|
instances.put(app.getClassName(), resource);
|
||||||
|
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
/** Load an App from its className and call its methods dynamically */
|
/** Load an App from its className and call its methods dynamically */
|
||||||
public static void runMethodFromApplication(
|
public static void runMethodFromApplication(
|
||||||
App app, CollectionDAO daoCollection, SearchRepository searchRepository, String methodName) {
|
App app, CollectionDAO daoCollection, SearchRepository searchRepository, String methodName) {
|
||||||
// Native Application
|
// Native Application
|
||||||
try {
|
try {
|
||||||
Class<?> clz = Class.forName(app.getClassName());
|
Object resource = getAppInstance(app.getClassName());
|
||||||
Object resource =
|
if (resource == null) {
|
||||||
clz.getDeclaredConstructor(CollectionDAO.class, SearchRepository.class)
|
resource = runAppInit(app, daoCollection, searchRepository);
|
||||||
.newInstance(daoCollection, searchRepository);
|
}
|
||||||
|
|
||||||
// Call init Method
|
|
||||||
Method initMethod = resource.getClass().getMethod("init", App.class);
|
|
||||||
initMethod.invoke(resource, app);
|
|
||||||
|
|
||||||
// Call method on demand
|
// Call method on demand
|
||||||
Method scheduleMethod = resource.getClass().getMethod(methodName);
|
Method scheduleMethod = resource.getClass().getMethod(methodName);
|
||||||
|
@ -164,12 +164,12 @@ public class AppRepository extends EntityRepository<App> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<AppRunRecord> listAll() {
|
public final List<App> listAll() {
|
||||||
// forward scrolling, if after == null then first page is being asked
|
// forward scrolling, if after == null then first page is being asked
|
||||||
List<String> jsons = dao.listAfterWithOffset(Integer.MAX_VALUE, 0);
|
List<String> jsons = dao.listAfterWithOffset(Integer.MAX_VALUE, 0);
|
||||||
List<AppRunRecord> entities = new ArrayList<>();
|
List<App> entities = new ArrayList<>();
|
||||||
for (String json : jsons) {
|
for (String json : jsons) {
|
||||||
AppRunRecord entity = JsonUtils.readValue(json, AppRunRecord.class);
|
App entity = JsonUtils.readValue(json, App.class);
|
||||||
entities.add(entity);
|
entities.add(entity);
|
||||||
}
|
}
|
||||||
return entities;
|
return entities;
|
||||||
|
@ -143,6 +143,21 @@ public class AppResource extends EntityResource<App, AppRepository> {
|
|||||||
ApplicationHandler.installApplication(app, Entity.getCollectionDAO(), searchRepository);
|
ApplicationHandler.installApplication(app, Entity.getCollectionDAO(), searchRepository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize installed applications
|
||||||
|
for (App installedApp : repository.listAll()) {
|
||||||
|
App appWithBot = getAppForInit(installedApp.getName());
|
||||||
|
if (appWithBot == null) {
|
||||||
|
LOG.error(
|
||||||
|
String.format(
|
||||||
|
"Failed to init app [%s]. GET should return the installed app",
|
||||||
|
installedApp.getName()));
|
||||||
|
} else {
|
||||||
|
setAppRuntimeProperties(appWithBot);
|
||||||
|
ApplicationHandler.runAppInit(appWithBot, dao, searchRepository);
|
||||||
|
LOG.info(String.format("Initialized installed app [%s]", installedApp.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Failed in Create App Requests", ex);
|
LOG.error("Failed in Create App Requests", ex);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ReadRows",
|
"name": "ReadRows",
|
||||||
"description": "Validate that we can read rows with the given credentials.",
|
"description": "Validate that we can read rows with the given credentials.",
|
||||||
"errorMessage": "Failed to read rows from BigTable, please validate to the credentials of service account"
|
"errorMessage": "Failed to read rows from BigTable, please validate to the credentials of service account",
|
||||||
"shortCircuit": true,
|
"shortCircuit": true,
|
||||||
"mandatory": true
|
"mandatory": true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user