You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/01/30 07:23:57 UTC

[incubator-linkis] branch dev-1.1.0-datasource updated (5367438 -> 823711c)

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a change to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git.


    from 5367438  jetty 9.4.44.v20210927 (#1354)
     new cdbeeb9  add module linkis-metadata-manager-server
     new 78b21fa  add mvn assembly plugin and dependency
     new 7fa881c  add entry main class
     new 5f4c28f  define metadata utils class
     new b37ed69  add meta class loader manager
     new 2156083  define service interface and implement class
     new 823711c  add restful api

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../linkis-metadata-manager/server}/pom.xml        |  50 +++--
 .../server}/src/main/assembly/distribution.xml     |  76 +++++---
 .../server/LinkisMetadataManagerApplication.java}  |   8 +-
 .../server/loader/MetaClassLoaderManager.java      | 201 +++++++++++++++++++++
 .../server/restful/MetadataCoreRestful.java        | 159 ++++++++++++++++
 .../server/service/MetadataAppService.java         |  20 +-
 .../service/impl/MetadataAppServiceImpl.java       | 189 +++++++++++++++++++
 .../server/utils/MetadataUtils.java                | 157 ++++++++++++++++
 .../linkis-datasource/pom.xml                      |   1 +
 9 files changed, 798 insertions(+), 63 deletions(-)
 copy linkis-public-enhancements/{ => linkis-datasource/linkis-metadata-manager/server}/pom.xml (76%)
 copy {linkis-engineconn-plugins/engineconn-plugins/python => linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server}/src/main/assembly/distribution.xml (53%)
 copy linkis-public-enhancements/linkis-datasource/{linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/LinkisDataSourceManagerApplication.java => linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/LinkisMetadataManagerApplication.java} (79%)
 create mode 100644 linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/loader/MetaClassLoaderManager.java
 create mode 100644 linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/restful/MetadataCoreRestful.java
 copy linkis-public-enhancements/linkis-datasource/{metadatamanager => linkis-metadata-manager}/server/src/main/java/org/apache/linkis/metadatamanager/server/service/MetadataAppService.java (76%)
 create mode 100644 linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/service/impl/MetadataAppServiceImpl.java
 create mode 100644 linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/utils/MetadataUtils.java

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org


[incubator-linkis] 04/07: define metadata utils class

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit 5f4c28fc8aa0537e408dfde1d8d56700c7ada679
Author: xiaojie19852006 <xi...@163.com>
AuthorDate: Sun Jan 30 13:57:13 2022 +0800

    define metadata utils class
---
 .../server/utils/MetadataUtils.java                | 157 +++++++++++++++++++++
 1 file changed, 157 insertions(+)

diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/utils/MetadataUtils.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/utils/MetadataUtils.java
new file mode 100644
index 0000000..51d56a2
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/utils/MetadataUtils.java
@@ -0,0 +1,157 @@
+/*
+ * 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.apache.linkis.metadatamanager.server.utils;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.linkis.metadatamanager.common.exception.MetaRuntimeException;
+import org.apache.linkis.metadatamanager.common.service.MetadataService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.*;
+import java.util.function.Function;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.stream.Collectors;
+
+/**
+ * Metadata Utils
+ */
+public class MetadataUtils {
+
+    private static final String JAR_SUF_NAME = ".jar";
+
+    private static final String CLASS_SUF_NAME = ".class";
+
+    private static final Logger LOG = LoggerFactory.getLogger(MetadataUtils.class);
+
+    public static MetadataService loadMetaService(Class<? extends MetadataService> metaServiceClass,
+                                                  ClassLoader metaServiceClassLoader){
+        ClassLoader storeClassLoader = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(metaServiceClassLoader);
+        try{
+            final Constructor<?>[] constructors = metaServiceClass.getConstructors();
+            if (constructors.length <= 0){
+                throw new MetaRuntimeException("No public constructor in meta service class: [" + metaServiceClass.getName() + "]", null);
+            }
+            List<Constructor<?>> acceptConstructor = Arrays.stream(constructors)
+                    .filter( constructor -> constructor.getParameterCount() == 0).collect(Collectors.toList());
+            if (acceptConstructor.size() > 0){
+                //Choose the first one
+                Constructor<?> constructor = acceptConstructor.get(0);
+                try {
+                    return (MetadataService)constructor.newInstance();
+                } catch (Exception e) {
+                    throw new MetaRuntimeException("Unable to construct meta service class: [" + metaServiceClass.getName() + "]", e);
+                }
+            }else{
+                throw new MetaRuntimeException("Illegal arguments in constructor of meta service class: [" + metaServiceClass.getName() + "]", null);
+            }
+        }finally{
+            Thread.currentThread().setContextClassLoader(storeClassLoader);
+        }
+    }
+    /**
+     * Search meta service class from classloader
+     * @param serviceClassLoader service class loader
+     * @return collect
+     */
+    public static String[] searchMetaServiceClassInLoader(URLClassLoader serviceClassLoader){
+        URL[] urlsOfClassLoader = serviceClassLoader.getURLs();
+        List<String> classNameList = new ArrayList<>();
+        for( URL url : urlsOfClassLoader ){
+            String pathForUrl = url.getPath();
+             List<String> searchResult = searchMetaServiceClassFormURI(pathForUrl, className -> isSubMetaServiceClass(className, serviceClassLoader));
+             if (Objects.nonNull(searchResult)){
+                 classNameList.addAll(searchResult);
+             }
+        }
+        return classNameList.toArray(new String[]{});
+    }
+
+    public static Class<? extends MetadataService> loadMetaServiceClass(ClassLoader classLoader, String className,
+                                                                        boolean initialize, String notFoundMessage){
+        //Try to load use expectClassName
+        try {
+           return Class.forName(className, initialize, classLoader).asSubclass(MetadataService.class);
+        }catch(ClassNotFoundException ne){
+            LOG.warn(notFoundMessage, ne);
+        }
+        return null;
+    }
+
+    private static List<String> searchMetaServiceClassFormURI(String url, Function<String, Boolean> acceptedFunction){
+        List<String> classNameList = new ArrayList<>();
+        if(url.endsWith(CLASS_SUF_NAME)){
+            String className = url.substring(0, url.lastIndexOf(CLASS_SUF_NAME));
+            int splitIndex = className.lastIndexOf(IOUtils.DIR_SEPARATOR);
+            if(splitIndex >= 0){
+                className = className.substring(splitIndex);
+            }
+            if (acceptedFunction.apply(className)){
+                classNameList.add(className);
+            }
+        }else if(url.endsWith(JAR_SUF_NAME)){
+            try {
+                JarFile jarFile = new JarFile(new File(url));
+                Enumeration<JarEntry> en = jarFile.entries();
+                while(en.hasMoreElements()){
+                    String name = en.nextElement().getName();
+                    if(name.endsWith(CLASS_SUF_NAME)){
+                        String className = name.substring(0, name.lastIndexOf(CLASS_SUF_NAME));
+                        //If the splicer is different in WINDOWS system?
+                        className = className.replaceAll(String.valueOf(IOUtils.DIR_SEPARATOR_UNIX), ".");
+                        if(acceptedFunction.apply(className)){
+                           classNameList.add(className);
+                        }
+                    }
+                }
+            } catch (IOException e) {
+                //Trace
+                LOG.trace("Fail to parse jar file:[" + url + "] in service classpath", e);
+                return classNameList;
+            }
+        }
+        return classNameList;
+    }
+
+    private static boolean isSubMetaServiceClass(String className, ClassLoader serviceClassLoader){
+        if(StringUtils.isEmpty(className)){
+            return false;
+        }
+        Class<?> clazz;
+        try{
+            clazz = Class.forName(className, false, serviceClassLoader);
+            //Skip interface and abstract class
+            if (Modifier.isAbstract(clazz.getModifiers()) || Modifier.isInterface(clazz.getModifiers())) {
+                return false;
+            }
+        } catch (Throwable t){
+            LOG.trace("Class: {} can not be found", className, t);
+            return false;
+        }
+        return MetadataService.class.isAssignableFrom(clazz);
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org


[incubator-linkis] 03/07: add entry main class

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit 7fa881cbbd9f6e1396720116e773b951d834e5f9
Author: xiaojie19852006 <xi...@163.com>
AuthorDate: Sun Jan 30 13:56:09 2022 +0800

    add entry main class
---
 .../server/LinkisMetadataManagerApplication.java   | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/LinkisMetadataManagerApplication.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/LinkisMetadataManagerApplication.java
new file mode 100644
index 0000000..8f7c5b2
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/LinkisMetadataManagerApplication.java
@@ -0,0 +1,33 @@
+/*
+ * 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.apache.linkis.metadatamanager.server;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.linkis.LinkisBaseServerApp;
+
+
+public class LinkisMetadataManagerApplication {
+
+    private static final Log logger = LogFactory.getLog(LinkisMetadataManagerApplication.class);
+
+    public static void main(String[] args) throws ReflectiveOperationException {
+        logger.info("Start to running LinkisMetadataManagerApplication");
+        LinkisBaseServerApp.main(args);
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org


[incubator-linkis] 02/07: add mvn assembly plugin and dependency

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit 78b21fa3ab5668f4053b8be815c0289b392ba539
Author: xiaojie19852006 <xi...@163.com>
AuthorDate: Sun Jan 30 13:54:16 2022 +0800

    add mvn assembly plugin and dependency
---
 .../linkis-metadata-manager/server/pom.xml         | 105 +++++++++++++++++++--
 .../server/src/main/assembly/distribution.xml      | 103 ++++++++++++++++++++
 2 files changed, 202 insertions(+), 6 deletions(-)

diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/pom.xml b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/pom.xml
index 819bbbd..73191ca 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/pom.xml
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/pom.xml
@@ -1,20 +1,113 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
         <artifactId>linkis</artifactId>
         <groupId>org.apache.linkis</groupId>
         <version>1.0.3</version>
-        <relativePath>../../../../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-
     <artifactId>linkis-metadata-manager-server</artifactId>
 
     <properties>
-        <maven.compiler.source>8</maven.compiler.source>
-        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 
+    <dependencies>
+        <!--Metadata common-->
+        <dependency>
+            <groupId>org.apache.linkis</groupId>
+            <artifactId>linkis-metadata-manager-common</artifactId>
+            <version>${linkis.version}</version>
+        </dependency>
+        <!-- data source manager common dependency-->
+        <dependency>
+            <groupId>org.apache.linkis</groupId>
+            <artifactId>linkis-datasource-manager-common</artifactId>
+            <version>${linkis.version}</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>asm</artifactId>
+                    <groupId>org.ow2.asm</groupId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <!--rpc-->
+        <dependency>
+            <groupId>org.apache.linkis</groupId>
+            <artifactId>linkis-rpc</artifactId>
+            <version>${linkis.version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>net.alchim31.maven</groupId>
+                <artifactId>scala-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>2.3</version>
+                <inherited>false</inherited>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                        <configuration>
+                            <descriptors>
+                                <descriptor>src/main/assembly/distribution.xml</descriptor>
+                            </descriptors>
+                        </configuration>
+                    </execution>
+                </executions>
+                <configuration>
+                    <skipAssembly>false</skipAssembly>
+                    <finalName>out</finalName>
+                    <appendAssemblyId>false</appendAssemblyId>
+                    <attach>false</attach>
+                    <descriptors>
+                        <descriptor>src/main/assembly/distribution.xml</descriptor>
+                    </descriptors>
+                </configuration>
+            </plugin>
+        </plugins>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+        </resources>
+        <finalName>${project.artifactId}-${project.version}</finalName>
+    </build>
 </project>
\ No newline at end of file
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/assembly/distribution.xml b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/assembly/distribution.xml
new file mode 100644
index 0000000..4ce2921
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/assembly/distribution.xml
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <!--
+  ~ 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.
+  -->
+
+<assembly
+        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.3"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.3 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
+    <id>linkis-metadata-manager-server</id>
+    <formats>
+        <format>zip</format>
+        <format>dir</format>
+    </formats>
+    <includeBaseDirectory>false</includeBaseDirectory>
+    <baseDirectory>linkis-mdm-server</baseDirectory>
+
+    <dependencySets>
+        <dependencySet>
+            <!-- Enable access to all projects in the current multimodule build! <useAllReactorProjects>true</useAllReactorProjects> -->
+            <!-- Now, select which projects to include in this module-set. -->
+            <outputDirectory>lib</outputDirectory>
+            <useProjectArtifact>true</useProjectArtifact>
+            <useTransitiveDependencies>true</useTransitiveDependencies>
+            <unpack>false</unpack>
+            <useStrictFiltering>true</useStrictFiltering>
+            <useTransitiveFiltering>true</useTransitiveFiltering>
+        </dependencySet>
+    </dependencySets>
+
+    <fileSets>
+        <fileSet>
+            <directory>${basedir}/../service/elasticsearch/target/out/lib</directory>
+            <fileMode>0755</fileMode>
+            <outputDirectory>lib/service/elasticsearch</outputDirectory>
+            <includes>
+                <include>*.jar</include>
+            </includes>
+            <excludes>
+                <exclude>*-javadoc.jar</exclude>
+            </excludes>
+        </fileSet>
+        <fileSet>
+            <directory>${basedir}/../service/hive/target/out/lib</directory>
+            <fileMode>0755</fileMode>
+            <outputDirectory>lib/service/hive</outputDirectory>
+            <includes>
+                <include>*.jar</include>
+            </includes>
+            <excludes>
+                <exclude>*-javadoc.jar</exclude>
+            </excludes>
+        </fileSet>
+        <fileSet>
+            <directory>${basedir}/../service/kafka/target/out/lib</directory>
+            <fileMode>0755</fileMode>
+            <outputDirectory>lib/service/kafka</outputDirectory>
+            <includes>
+                <include>*.jar</include>
+            </includes>
+            <excludes>
+                <exclude>*-javadoc.jar</exclude>
+            </excludes>
+        </fileSet>
+        <fileSet>
+            <directory>${basedir}/../service/mysql/target/out/lib</directory>
+            <fileMode>0755</fileMode>
+            <outputDirectory>lib/service/mysql</outputDirectory>
+            <includes>
+                <include>*.jar</include>
+            </includes>
+            <excludes>
+                <exclude>*-javadoc.jar</exclude>
+            </excludes>
+        </fileSet>
+        <fileSet>
+            <directory>${basedir}/../service/tdsql/target/out/lib</directory>
+            <fileMode>0755</fileMode>
+            <outputDirectory>lib/service/tdsql</outputDirectory>
+            <includes>
+                <include>*.jar</include>
+            </includes>
+            <excludes>
+                <exclude>*-javadoc.jar</exclude>
+            </excludes>
+        </fileSet>
+    </fileSets>
+
+</assembly>
+

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org


[incubator-linkis] 05/07: add meta class loader manager

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit b37ed69cb6a92d889a28f49581c9295c4487b160
Author: xiaojie19852006 <xi...@163.com>
AuthorDate: Sun Jan 30 13:58:24 2022 +0800

    add meta class loader manager
---
 .../server/loader/MetaClassLoaderManager.java      | 201 +++++++++++++++++++++
 1 file changed, 201 insertions(+)

diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/loader/MetaClassLoaderManager.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/loader/MetaClassLoaderManager.java
new file mode 100644
index 0000000..046c4a5
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/loader/MetaClassLoaderManager.java
@@ -0,0 +1,201 @@
+/*
+ * 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.apache.linkis.metadatamanager.server.loader;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.common.exception.ErrorException;
+import org.apache.linkis.metadatamanager.common.exception.MetaRuntimeException;
+import org.apache.linkis.metadatamanager.common.service.AbstractMetaService;
+import org.apache.linkis.metadatamanager.common.service.MetadataService;
+import org.apache.linkis.metadatamanager.server.utils.MetadataUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+
+/**
+ * Class Loader for metaClass
+ * // TODO used interface class
+ */
+public class MetaClassLoaderManager {
+
+    private final Map<String, ClassLoader> classLoaders = new ConcurrentHashMap<>();
+
+    private final Map<String, MetaServiceInstance> metaServiceInstances = new ConcurrentHashMap<>();
+
+    public static CommonVars<String> LIB_DIR = CommonVars.apply("wds.linkis.server.mdm.service.lib.dir", "/lib/linkis-pulicxxxx-/linkis-metdata-manager/service");
+
+    public static CommonVars<Integer> INSTANCE_EXPIRE_TIME = CommonVars.apply("wds.linkis.server.mdm.service.instance.expire-in-seconds", 60);
+
+    private static final String META_CLASS_NAME = "com.webank.wedatasphere.linkis.metadatamanager.service.%sMetaService";
+
+    private static final Logger LOG = LoggerFactory.getLogger(MetaClassLoaderManager.class);
+
+    public BiFunction<String, Object[], Object> getInvoker(String dsType) throws ErrorException {
+        boolean needToLoad = true;
+        MetaServiceInstance serviceInstance = metaServiceInstances.get(dsType);
+        if (Objects.nonNull(serviceInstance)){
+            Integer expireTimeInSec = INSTANCE_EXPIRE_TIME.getValue();
+            //Lazy load
+            needToLoad = Objects.nonNull(expireTimeInSec) && expireTimeInSec > 0 &&
+                    (serviceInstance.initTimeStamp +
+                            TimeUnit.MILLISECONDS.convert(expireTimeInSec,  TimeUnit.SECONDS)) < System.currentTimeMillis();
+        }
+        if(needToLoad) {
+            MetaServiceInstance finalServiceInstance1 = serviceInstance;
+            serviceInstance = metaServiceInstances.compute(dsType, (key, instance) -> {
+                if(null != instance && !Objects.equals(finalServiceInstance1, instance)){
+                    return instance;
+                }
+                LOG.info("Start to load/reload meta instance of data source type: [" + dsType + "]");
+                ClassLoader parentClassLoader = MetaClassLoaderManager.class.getClassLoader();
+                ClassLoader metaClassLoader = classLoaders.compute(dsType, (type, classLoader) -> {
+                    String lib = LIB_DIR.getValue();
+                    String stdLib = lib.endsWith("/") ? lib.replaceAll(".$", "") : lib;
+                    String componentLib = stdLib + "/" + dsType;
+                    try {
+                        return new URLClassLoader(getJarsUrlsOfPath(componentLib).toArray(new URL[0]), parentClassLoader);
+                    } catch (Exception e) {
+                        LOG.error("Cannot init the classloader of type: [" + dsType + "] in library path: [" + componentLib + "]", e);
+                        return null;
+                    }
+                });
+                if (Objects.isNull(metaClassLoader)) {
+                    throw new MetaRuntimeException("Error in creating classloader of type: [" + dsType + "]", null);
+                }
+                String expectClassName = null;
+                if (dsType.length() > 0) {
+                    String prefix = dsType.substring(0, 1).toUpperCase() + dsType.substring(1);
+                    expectClassName = String.format(META_CLASS_NAME, prefix);
+                }
+                Class<? extends MetadataService> metaServiceClass = searchForLoadMetaServiceClass(metaClassLoader, expectClassName, true);
+                if (Objects.isNull(metaServiceClass)) {
+                    throw new MetaRuntimeException("Fail to init and load meta service class for type: [" + dsType + "]", null);
+                }
+                MetadataService metadataService = MetadataUtils.loadMetaService(metaServiceClass, metaClassLoader);
+                if (metadataService instanceof AbstractMetaService){
+                    LOG.info("Invoke the init() method in meta service for type: [" + dsType +"]");
+                    ((AbstractMetaService<?>)metadataService).init();
+                }
+                return new MetaServiceInstance(metadataService, metaClassLoader);
+            });
+        }
+        Method[] childMethods = serviceInstance.methods;
+        MetaServiceInstance finalServiceInstance = serviceInstance;
+        return (String m, Object...args)-> {
+            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(finalServiceInstance.metaClassLoader);
+                Method method = Arrays.stream(childMethods)
+                        .filter(eachMethod -> eachMethod.getName().equals(m)).collect(Collectors.toList()).get(0);
+                return method.invoke(finalServiceInstance.serviceInstance, args);
+            } catch (Exception e) {
+                Throwable t = e;
+                // UnWrap the Invocation target exception
+                while (t instanceof InvocationTargetException){
+                    t = t.getCause();
+                }
+                String message = "Fail to invoke method: [" + m + "] in meta service instance: [" + finalServiceInstance.serviceInstance.toString() + "]";
+                LOG.warn(message, t);
+                throw new MetaRuntimeException(message, t);
+            }finally {
+                Thread.currentThread().setContextClassLoader(currentClassLoader);
+            }
+        };
+    }
+
+
+
+
+    private Class<? extends MetadataService> searchForLoadMetaServiceClass(ClassLoader classLoader,
+                                                                           String expectClassName, boolean initialize){
+        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(classLoader);
+        try{
+            Class<? extends MetadataService> metaClass = null;
+            if(StringUtils.isNotBlank(expectClassName)){
+                metaClass = MetadataUtils.loadMetaServiceClass(classLoader, expectClassName,
+                        initialize, "Cannot find class in using expect class name: [" + expectClassName + "]");
+            }
+            if (Objects.isNull(metaClass)){
+                if (classLoader instanceof URLClassLoader){
+                    String[] metaServiceClassNames = MetadataUtils.searchMetaServiceClassInLoader((URLClassLoader)classLoader);
+                    if (metaServiceClassNames.length > 0){
+                        String metaServiceClassName = metaServiceClassNames[0];
+                        metaClass = MetadataUtils.loadMetaServiceClass(classLoader, metaServiceClassName,
+                                initialize, "Cannot load class in canonical name: [" + metaServiceClassName + "], please check the compiled jar/file");
+                    }
+                }
+            }
+            return metaClass;
+        } finally{
+            Thread.currentThread().setContextClassLoader(currentClassLoader);
+        }
+    }
+
+
+    private List<URL> getJarsUrlsOfPath(String path) throws MalformedURLException {
+        File file = new File(path);
+        List<URL> jars = new ArrayList<>();
+        if (file.listFiles() != null){
+            for(File f : Objects.requireNonNull(file.listFiles())){
+                if (!f.isDirectory() && f.getName().endsWith(".jar")){
+                    jars.add(f.toURI().toURL());
+                }else if(f.isDirectory()){
+                    jars.addAll(getJarsUrlsOfPath(f.getPath()));
+                }
+            }
+        }
+        return jars;
+    }
+
+    /**
+     * ServiceInstance Holder
+     */
+    public static class MetaServiceInstance{
+        private MetadataService serviceInstance;
+
+        private Method[] methods;
+
+        private ClassLoader metaClassLoader;
+
+        private long initTimeStamp = 0L;
+
+        public MetaServiceInstance(MetadataService serviceInstance, ClassLoader metaClassLoader){
+            this.serviceInstance = serviceInstance;
+            this.metaClassLoader = metaClassLoader;
+            this.methods = serviceInstance.getClass().getMethods();
+            this.initTimeStamp = System.currentTimeMillis();
+        }
+
+        public MetadataService getServiceInstance() {
+            return serviceInstance;
+        }
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org


[incubator-linkis] 06/07: define service interface and implement class

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit 21560839242a5200481f532de8d17ff48035a2f2
Author: xiaojie19852006 <xi...@163.com>
AuthorDate: Sun Jan 30 14:00:48 2022 +0800

    define service interface and implement class
---
 .../server/service/MetadataAppService.java         |  79 +++++++++
 .../service/impl/MetadataAppServiceImpl.java       | 189 +++++++++++++++++++++
 2 files changed, 268 insertions(+)

diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/service/MetadataAppService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/service/MetadataAppService.java
new file mode 100644
index 0000000..80d90b3
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/service/MetadataAppService.java
@@ -0,0 +1,79 @@
+/*
+ * 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.apache.linkis.metadatamanager.server.service;
+
+import org.apache.linkis.common.exception.ErrorException;
+import org.apache.linkis.metadatamanager.common.domain.MetaColumnInfo;
+import org.apache.linkis.metadatamanager.common.domain.MetaPartitionInfo;
+
+import java.util.List;
+import java.util.Map;
+
+public interface MetadataAppService {
+
+    /**
+     * Get connection
+     * @param params connect params
+     * @return
+     */
+    void getConnection(String dataSourceType, String operator, Map<String, Object> params) throws Exception;
+
+    /**
+     * @param dataSourceId data source id
+     * @param system system
+     * @return
+     */
+    List<String> getDatabasesByDsId(String dataSourceId, String system, String userName) throws ErrorException;
+
+    /**
+     * @param dataSourceId data source id
+     * @param system system
+     * @param database database
+     * @return
+     */
+    List<String> getTablesByDsId(String dataSourceId, String database, String system, String userName) throws ErrorException;
+
+    /**
+     * @param dataSourceId data source id
+     * @param database database
+     * @param table table
+     * @param system system
+     * @return
+     */
+    Map<String, String> getTablePropsByDsId(String dataSourceId, String database, String table,
+                                            String system, String userName) throws ErrorException;
+    /**
+     * @param dataSourceId data source i
+     * @param database database
+     * @param table table
+     * @param system system
+     * @return
+     */
+    MetaPartitionInfo getPartitionsByDsId(String dataSourceId, String database, String table,
+                                          String system, String userName) throws ErrorException;
+
+    /**
+     * @param dataSourceId data source id
+     * @param database database
+     * @param table table
+     * @param system system
+     * @return
+     */
+    List<MetaColumnInfo> getColumns(String dataSourceId, String database, String table,
+                                    String system, String userName) throws ErrorException;
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/service/impl/MetadataAppServiceImpl.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/service/impl/MetadataAppServiceImpl.java
new file mode 100644
index 0000000..7e2bab1
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/service/impl/MetadataAppServiceImpl.java
@@ -0,0 +1,189 @@
+/*
+ * 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.apache.linkis.metadatamanager.server.service.impl;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.linkis.common.exception.ErrorException;
+import org.apache.linkis.datasourcemanager.common.auth.AuthContext;
+import org.apache.linkis.datasourcemanager.common.protocol.DsInfoQueryRequest;
+import org.apache.linkis.datasourcemanager.common.protocol.DsInfoResponse;
+import org.apache.linkis.metadatamanager.common.MdmConfiguration;
+import org.apache.linkis.metadatamanager.common.domain.MetaColumnInfo;
+import org.apache.linkis.metadatamanager.common.domain.MetaPartitionInfo;
+import org.apache.linkis.metadatamanager.common.exception.MetaMethodInvokeException;
+import org.apache.linkis.metadatamanager.common.exception.MetaRuntimeException;
+import org.apache.linkis.metadatamanager.common.service.MetadataConnection;
+import org.apache.linkis.metadatamanager.server.loader.MetaClassLoaderManager;
+import org.apache.linkis.metadatamanager.server.service.MetadataAppService;
+import org.apache.linkis.rpc.Sender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.*;
+import java.util.function.BiFunction;
+
+@Service
+public class MetadataAppServiceImpl implements MetadataAppService {
+    private Sender dataSourceRpcSender;
+    private MetaClassLoaderManager metaClassLoaderManager;
+    private static final Logger LOG = LoggerFactory.getLogger(MetadataAppServiceImpl.class);
+    @PostConstruct
+    public void init(){
+        dataSourceRpcSender = Sender.getSender(MdmConfiguration.DATA_SOURCE_SERVICE_APPLICATION.getValue());
+        metaClassLoaderManager = new MetaClassLoaderManager();
+    }
+
+
+    @Override
+    public void getConnection(String dataSourceType, String operator, Map<String, Object> params) throws Exception {
+        MetadataConnection<Closeable> metadataConnection = invokeMetaMethod(dataSourceType, "getConnection", new Object[]{operator, params}, Map.class);
+        if (Objects.nonNull(metadataConnection)){
+            Closeable connection = metadataConnection.getConnection();
+            try {
+                connection.close();
+            }catch(IOException e){
+                LOG.warn("Fail to close connection[关闭连接失败], [" + e.getMessage() + "]", e);
+            }
+        }
+    }
+
+    @Override
+    public List<String> getDatabasesByDsId(String dataSourceId, String system, String userName) throws ErrorException {
+        DsInfoResponse dsInfoResponse = reqToGetDataSourceInfo(dataSourceId, system, userName);
+        if(StringUtils.isNotBlank(dsInfoResponse.dsType())){
+            return invokeMetaMethod(dsInfoResponse.dsType(), "getDatabases",   new Object[]{dsInfoResponse.creator(), dsInfoResponse.params()}, List.class);
+        }
+        return new ArrayList<>();
+    }
+
+    @Override
+    public List<String> getTablesByDsId(String dataSourceId, String database, String system,
+                                        String userName) throws ErrorException {
+        DsInfoResponse dsInfoResponse = reqToGetDataSourceInfo(dataSourceId, system, userName);
+        if(StringUtils.isNotBlank(dsInfoResponse.dsType())){
+            return invokeMetaMethod(dsInfoResponse.dsType(), "getTables", new Object[]{dsInfoResponse.creator(), dsInfoResponse.params(), database}, List.class);
+        }
+        return new ArrayList<>();
+    }
+
+    @Override
+    public Map<String, String> getTablePropsByDsId(String dataSourceId, String database, String table,
+                                                   String system, String userName) throws ErrorException {
+        DsInfoResponse dsInfoResponse = reqToGetDataSourceInfo(dataSourceId, system, userName);
+        if(StringUtils.isNotBlank(dsInfoResponse.dsType())){
+            return invokeMetaMethod(dsInfoResponse.dsType(), "getTableProps",  new Object[]{dsInfoResponse.creator(), dsInfoResponse.params(), database, table},
+                    Map.class);
+        }
+        return new HashMap<>();
+    }
+
+    @Override
+    public MetaPartitionInfo getPartitionsByDsId(String dataSourceId, String database, String table,
+                                                 String system, String userName) throws ErrorException {
+        DsInfoResponse dsInfoResponse = reqToGetDataSourceInfo(dataSourceId, system, userName);
+        if(StringUtils.isNotBlank(dsInfoResponse.dsType())){
+            return invokeMetaMethod(dsInfoResponse.dsType(), "getPartitions", new Object[]{dsInfoResponse.creator(), dsInfoResponse.params(), database, table},
+                    MetaPartitionInfo.class);
+        }
+        return new MetaPartitionInfo();
+    }
+
+    @Override
+    public List<MetaColumnInfo> getColumns(String dataSourceId, String database, String table,
+                                           String system, String userName) throws ErrorException {
+        DsInfoResponse dsInfoResponse = reqToGetDataSourceInfo(dataSourceId, system, userName);
+        if(StringUtils.isNotBlank(dsInfoResponse.dsType())){
+            return invokeMetaMethod(dsInfoResponse.dsType(), "getColumns", new Object[]{dsInfoResponse.creator(), dsInfoResponse.params(), database, table},
+                    List.class);
+        }
+        return new ArrayList<>();
+    }
+
+    /**
+     * Request to get data source information
+     * (type and connection parameters)
+     * @param dataSourceId data source id
+     * @param system system
+     * @return
+     * @throws ErrorException
+     */
+    public DsInfoResponse reqToGetDataSourceInfo(String dataSourceId, String system,
+                                                 String userName) throws ErrorException{
+        Object rpcResult = null;
+        try {
+            rpcResult = dataSourceRpcSender.ask(new DsInfoQueryRequest(dataSourceId, null, system));
+        }catch(Exception e){
+            throw new ErrorException(-1, "Remote Service Error[远端服务出错, 联系运维处理]");
+        }
+        if(rpcResult instanceof DsInfoResponse){
+            DsInfoResponse response = (DsInfoResponse)rpcResult;
+            if(!response.status()){
+                throw new ErrorException(-1, "Error in Data Source Manager Server[数据源服务出错]");
+            }
+            boolean hasPermission = (AuthContext.isAdministrator(userName) ||
+                    (StringUtils.isNotBlank(response.creator()) && userName.equals(response.creator())));
+            if(!hasPermission){
+                throw new ErrorException(-1, "Don't have query permission for data source [没有数据源的查询权限]");
+            } else if (response.params().isEmpty()){
+                throw new ErrorException(-1, "Have you published the data source? [数据源未发布或者参数为空]");
+            }
+            return response;
+        }else{
+            throw new ErrorException(-1, "Remote Service Error[远端服务出错, 联系运维处理]");
+        }
+    }
+
+    /**
+     * Invoke method in meta service
+     * @param method method name
+     * @param methodArgs arguments
+     */
+    @SuppressWarnings("unchecked")
+    private <T>T invokeMetaMethod(String dsType,
+                                  String method, Object[] methodArgs,
+                                  Class<?> returnType) throws MetaMethodInvokeException {
+        BiFunction<String, Object[], Object> invoker;
+        try {
+            invoker = metaClassLoaderManager.getInvoker(dsType);
+        }catch (Exception e){
+            // TODO ERROR CODE
+            throw new MetaMethodInvokeException(-1, "Load meta service for " + dsType +
+                    " fail 加载 [" + dsType + "] 元数据服务失败", e);
+        }
+        if (Objects.nonNull(invoker)){
+            try {
+                Object returnObj = invoker.apply(method, methodArgs);
+                if (Objects.nonNull(returnType)) {
+                    return (T) returnObj;
+                }
+            }catch (Exception e){
+                if (e instanceof MetaRuntimeException){
+                    throw new MetaMethodInvokeException(method, methodArgs, -1, e.getMessage(), e.getCause());
+                }
+                // TODO ERROR CODE
+                throw new MetaMethodInvokeException(method, methodArgs, -1,
+                        "Invoke method [" + method +"] fail, message:[" + e.getMessage() + "]", e);
+            }
+        }
+        return null;
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org


[incubator-linkis] 07/07: add restful api

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit 823711cbcc1d724da16e5b4f62103e659b83bbe1
Author: xiaojie19852006 <xi...@163.com>
AuthorDate: Sun Jan 30 14:01:43 2022 +0800

    add restful api
---
 .../server/restful/MetadataCoreRestful.java        | 159 +++++++++++++++++++++
 1 file changed, 159 insertions(+)

diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/restful/MetadataCoreRestful.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/restful/MetadataCoreRestful.java
new file mode 100644
index 0000000..0bcbe84
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/src/main/java/org/apache/linkis/metadatamanager/server/restful/MetadataCoreRestful.java
@@ -0,0 +1,159 @@
+/*
+ * 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.apache.linkis.metadatamanager.server.restful;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.linkis.common.exception.ErrorException;
+import org.apache.linkis.datasourcemanager.common.util.json.Json;
+import org.apache.linkis.metadatamanager.common.domain.MetaColumnInfo;
+import org.apache.linkis.metadatamanager.common.domain.MetaPartitionInfo;
+import org.apache.linkis.metadatamanager.common.exception.MetaMethodInvokeException;
+import org.apache.linkis.metadatamanager.server.service.MetadataAppService;
+import org.apache.linkis.server.Message;
+import org.apache.linkis.server.security.SecurityFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping(value = "/metadatamanager", produces = {"application/json"})
+public class MetadataCoreRestful {
+
+    private static final Logger LOG = LoggerFactory.getLogger(MetadataCoreRestful.class);
+
+    @Autowired
+    private MetadataAppService metadataAppService;
+
+    @RequestMapping(value = "/dbs/{data_source_id}", method = RequestMethod.GET)
+    public Message getDatabases(@PathVariable("data_source_id")String dataSourceId,
+                                 @RequestParam("system")String system,
+                                 HttpServletRequest request){
+        try{
+            if(StringUtils.isBlank(system)){
+                return Message.error("'system' is missing[缺少系统名]");
+            }
+            List<String> databases = metadataAppService.getDatabasesByDsId(dataSourceId, system,
+                    SecurityFilter.getLoginUsername(request));
+            return Message.ok().data("dbs", databases);
+        }catch(Exception e){
+            return errorToResponseMessage("Fail to get database list[获取库信息失败], id:[" + dataSourceId +"], system:[" + system + "]", e);
+        }
+    }
+
+    @RequestMapping( value = "/tables/{data_source_id}/db/{database}", method = RequestMethod.GET)
+    public Message getTables(@PathVariable("data_source_id")String dataSourceId,
+                              @PathVariable("database")String database,
+                              @RequestParam("system")String system,
+                              HttpServletRequest request){
+        try{
+            if(StringUtils.isBlank(system)){
+                return Message.error("'system' is missing[缺少系统名]");
+            }
+            List<String> tables = metadataAppService.getTablesByDsId(dataSourceId, database, system,
+                    SecurityFilter.getLoginUsername(request));
+            return Message.ok().data("tables", tables);
+        }catch(Exception e){
+            return errorToResponseMessage("Fail to get table list[获取表信息失败], id:[" + dataSourceId +"]" +
+                            ", system:[" + system + "], database:[" +database +"]", e);
+        }
+    }
+
+    @RequestMapping( value = "/props/{data_source_id}/db/{database}/table/{table}", method = RequestMethod.GET)
+    public Message getTableProps(@PathVariable("data_source_id")String dataSourceId,
+                                  @PathVariable("database")String database,
+                                  @PathVariable("table") String table,
+                                  @RequestParam("system")String system,
+                                   HttpServletRequest request){
+        try{
+            if(StringUtils.isBlank(system)){
+                return Message.error("'system' is missing[缺少系统名]");
+            }
+            Map<String, String> tableProps = metadataAppService.getTablePropsByDsId(dataSourceId, database, table, system,
+                    SecurityFilter.getLoginUsername(request));
+            return Message.ok().data("props", tableProps);
+        }catch(Exception e){
+            return errorToResponseMessage("Fail to get table properties[获取表参数信息失败], id:[" + dataSourceId +"]" +
+                            ", system:[" + system + "], database:[" +database +"], table:[" + table +"]", e);
+        }
+    }
+
+    @RequestMapping( value = "/partitions/{data_source_id}/db/{database}/table/{table}", method = RequestMethod.GET)
+    public Message getPartitions(@PathVariable("data_source_id")String dataSourceId,
+                                  @PathVariable("database")String database,
+                                  @PathVariable("table") String table,
+                                  @RequestParam("system")String system,
+                                   HttpServletRequest request){
+        try{
+            if(StringUtils.isBlank(system)){
+                return Message.error("'system' is missing[缺少系统名]");
+            }
+            MetaPartitionInfo partitionInfo = metadataAppService.getPartitionsByDsId(dataSourceId, database, table, system,
+                    SecurityFilter.getLoginUsername(request));
+            return Message.ok().data("props", partitionInfo);
+        }catch(Exception e){
+            return errorToResponseMessage("Fail to get partitions[获取表分区信息失败], id:[" + dataSourceId +"]" +
+                            ", system:[" + system + "], database:[" +database +"], table:[" + table +"]", e);
+        }
+    }
+
+    @RequestMapping( value = "/columns/{data_source_id}/db/{database}/table/{table}", method = RequestMethod.GET)
+    public Message getColumns(@PathVariable("data_source_id")String dataSourceId,
+                               @PathVariable("database")String database,
+                               @PathVariable("table") String table,
+                               @RequestParam("system")String system,
+                                HttpServletRequest request){
+        try{
+            if(StringUtils.isBlank(system)){
+                return Message.error("'system' is missing[缺少系统名]");
+            }
+            List<MetaColumnInfo> columns = metadataAppService.getColumns(dataSourceId, database, table, system,
+                    SecurityFilter.getLoginUsername(request));
+            return Message.ok().data("columns", columns);
+        }catch(Exception e){
+            return errorToResponseMessage("Fail to get column list[获取表字段信息失败], id:[" + dataSourceId +"]" +
+                            ", system:[" + system + "], database:[" +database +"], table:[" + table +"]", e);
+        }
+    }
+
+    private Message errorToResponseMessage(String uiMessage, Exception e){
+        if (e instanceof MetaMethodInvokeException){
+            MetaMethodInvokeException invokeException = (MetaMethodInvokeException)e;
+            if (LOG.isDebugEnabled()) {
+                String argumentJson = null;
+                try {
+                    argumentJson = Json.toJson(invokeException.getArgs(), null);
+                } catch (Exception je) {
+                    // Ignore
+                }
+                LOG.trace(uiMessage + " => Method: " + invokeException.getMethod() + ", Arguments:" + argumentJson, e);
+            }
+            uiMessage += " possible reason[可能原因]: (" + invokeException.getCause().getMessage() + ")";
+        }else {
+            if (e instanceof ErrorException){
+                uiMessage += " possible reason[可能原因]: (" + e.getMessage() + ")";
+            }
+           LOG.error(uiMessage, e);
+        }
+        return Message.error(uiMessage);
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org


[incubator-linkis] 01/07: add module linkis-metadata-manager-server

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.0-datasource
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit cdbeeb98b512ab9f846e7b6c4df47aed1ac45154
Author: xiaojie19852006 <xi...@163.com>
AuthorDate: Sun Jan 30 13:49:24 2022 +0800

    add module linkis-metadata-manager-server
---
 .../linkis-metadata-manager/server/pom.xml           | 20 ++++++++++++++++++++
 linkis-public-enhancements/linkis-datasource/pom.xml |  1 +
 2 files changed, 21 insertions(+)

diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/pom.xml b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/pom.xml
new file mode 100644
index 0000000..819bbbd
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-manager/server/pom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>linkis</artifactId>
+        <groupId>org.apache.linkis</groupId>
+        <version>1.0.3</version>
+        <relativePath>../../../../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>linkis-metadata-manager-server</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+</project>
\ No newline at end of file
diff --git a/linkis-public-enhancements/linkis-datasource/pom.xml b/linkis-public-enhancements/linkis-datasource/pom.xml
index 0b6a953..1ccb9c3 100644
--- a/linkis-public-enhancements/linkis-datasource/pom.xml
+++ b/linkis-public-enhancements/linkis-datasource/pom.xml
@@ -33,5 +33,6 @@
         <module>linkis-datasource-manager/common</module>
         <module>linkis-datasource-manager/server</module>
         <module>linkis-metadata-manager/common</module>
+        <module>linkis-metadata-manager/server</module>
     </modules>
 </project>
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org