Repository: atlas
Updated Branches:
  refs/heads/branch-0.8 218797aa4 -> 2e28afa96


ATLAS-2761: Removed dependency on Spring to support more versions in using 
Migration Exporter.

Signed-off-by: Ashutosh Mestry <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/2e28afa9
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/2e28afa9
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/2e28afa9

Branch: refs/heads/branch-0.8
Commit: 2e28afa96dd1507c5f477fbf413f6c3ba16f1fca
Parents: 218797a
Author: Ashutosh Mestry <[email protected]>
Authored: Mon Jun 18 22:38:18 2018 -0700
Committer: Ashutosh Mestry <[email protected]>
Committed: Fri Jun 22 14:02:56 2018 -0700

----------------------------------------------------------------------
 tools/atlas-migration-exporter/pom.xml          |  5 --
 .../org/apache/atlas/migration/Exporter.java    | 49 ++++++++++++++++----
 .../src/main/resources/migrationContext.xml     | 40 ----------------
 3 files changed, 41 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/2e28afa9/tools/atlas-migration-exporter/pom.xml
----------------------------------------------------------------------
diff --git a/tools/atlas-migration-exporter/pom.xml 
b/tools/atlas-migration-exporter/pom.xml
index 8ecd306..025d376 100644
--- a/tools/atlas-migration-exporter/pom.xml
+++ b/tools/atlas-migration-exporter/pom.xml
@@ -37,11 +37,6 @@
             <artifactId>commons-cli</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
-            <version>${spring.version}</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.atlas</groupId>
             <artifactId>atlas-notification</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/atlas/blob/2e28afa9/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java
----------------------------------------------------------------------
diff --git 
a/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java
 
b/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java
index 1bda19f..46f02b5 100644
--- 
a/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java
+++ 
b/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java
@@ -25,7 +25,9 @@ import org.apache.atlas.ApplicationProperties;
 import org.apache.atlas.AtlasException;
 import org.apache.atlas.ha.HAConfiguration;
 import org.apache.atlas.model.typedef.AtlasTypesDef;
+import org.apache.atlas.repository.graph.AtlasGraphProvider;
 import org.apache.atlas.repository.graphdb.titan0.Titan0GraphDatabase;
+import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
 import org.apache.atlas.type.AtlasType;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.commons.cli.BasicParser;
@@ -35,19 +37,18 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
+import java.util.HashSet;
 
 
 public class Exporter {
     private static final Logger LOG = LoggerFactory.getLogger(Exporter.class);
 
-    private static final String ATLAS_TYPE_REGISTRY         = 
"atlasTypeRegistry";
-    private static final String APPLICATION_CONTEXT         = 
"migrationContext.xml";
     private static final String MIGRATION_TYPESDEF_FILENAME = 
"atlas-migration-typesdef.json";
     private static final String MIGRATION_DATA_FILENAME     = 
"atlas-migration-data.json";
     private static final String LOG_MSG_PREFIX              = 
"atlas-migration-export: ";
@@ -79,7 +80,7 @@ public class Exporter {
             String typesDefFileName = outputDir + File.separatorChar + 
MIGRATION_TYPESDEF_FILENAME;
             String dataFileName     = outputDir + File.separatorChar + 
MIGRATION_DATA_FILENAME;
 
-            Exporter exporter = new Exporter(typesDefFileName, dataFileName, 
APPLICATION_CONTEXT);
+            Exporter exporter = new Exporter(typesDefFileName, dataFileName);
 
             exporter.perform();
 
@@ -95,21 +96,53 @@ public class Exporter {
         System.exit(result);
     }
 
-    public Exporter(String typesDefFileName, String dataFileName, String 
contextXml) throws Exception {
+    public Exporter(String typesDefFileName, String dataFileName) throws 
Exception {
         validate(typesDefFileName, dataFileName);
 
         displayMessage("initializing");
 
         resetHAMode();
-        ApplicationContext applicationContext = new 
ClassPathXmlApplicationContext(contextXml);
 
         this.typesDefFileName = typesDefFileName;
         this.dataFileName     = dataFileName;
-        this.typeRegistry     = 
applicationContext.getBean(ATLAS_TYPE_REGISTRY, AtlasTypeRegistry.class);;
 
+        typeRegistry                                 = new AtlasTypeRegistry();
+        AtlasTypeDefGraphStoreV1 typeDefGraphStoreV1 = 
createAtlasTypeDefGraphStoreV1(typeRegistry);
+        if(typeDefGraphStoreV1 == null) {
+            displayMessage("createAtlasTypeDefGraphStoreV1 returned null. 
Initialization failed!");
+            return;
+        }
+
+        typeDefGraphStoreV1.init();
         displayMessage("initialized");
     }
 
+    private AtlasTypeDefGraphStoreV1 
createAtlasTypeDefGraphStoreV1(AtlasTypeRegistry typeRegistry) {
+        Constructor[] ctors = 
AtlasTypeDefGraphStoreV1.class.getDeclaredConstructors();
+        if (ctors.length == 0 || (ctors[0].getParameterTypes().length == 0)) {
+            LOG.error("Appropriate ctors not found!");
+            return null;
+        }
+
+        Constructor ctor = ctors[0];
+        Class<?>[] parameterTypes = ctor.getParameterTypes();
+        try {
+            ctor.setAccessible(true);
+            displayMessage(String.format("ctor: parameters: %s", 
parameterTypes.length));
+            return (AtlasTypeDefGraphStoreV1) ((parameterTypes.length == 2) ?
+                    ctor.newInstance(typeRegistry, new HashSet<>()) :
+                    ctor.newInstance(typeRegistry, new HashSet<>(), 
AtlasGraphProvider.getGraphInstance()));
+        } catch (InstantiationException e) {
+            displayError("ctor", e);
+        } catch (IllegalAccessException e) {
+            displayError("ctor", e);
+        } catch (InvocationTargetException e) {
+            displayError("ctor", e);
+        }
+
+        return null;
+    }
+
     private void resetHAMode() throws AtlasException {
         ApplicationProperties applicationProperties = (ApplicationProperties) 
ApplicationProperties.get();
         
applicationProperties.setProperty(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY, 
false);

http://git-wip-us.apache.org/repos/asf/atlas/blob/2e28afa9/tools/atlas-migration-exporter/src/main/resources/migrationContext.xml
----------------------------------------------------------------------
diff --git 
a/tools/atlas-migration-exporter/src/main/resources/migrationContext.xml 
b/tools/atlas-migration-exporter/src/main/resources/migrationContext.xml
deleted file mode 100644
index c0f9659..0000000
--- a/tools/atlas-migration-exporter/src/main/resources/migrationContext.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?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. -->
-
-<beans xmlns="http://www.springframework.org/schema/beans";
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xmlns:context="http://www.springframework.org/schema/context";
-       xmlns:aop="http://www.springframework.org/schema/aop";
-       xsi:schemaLocation="http://www.springframework.org/schema/beans
-       http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop.xsd";>
-
-    <context:annotation-config/>
-    <aop:config proxy-target-class="true"/>
-
-    <context:component-scan base-package="org.apache.atlas">
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.service\.ActiveInstanceElectorService.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.service\.EmbeddedKafkaServer.*"/>
-        <!--<context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.service\.HBaseBasedAuditRepository.*"/>-->
-        <!-- for non-HBase setups comment the InMemoryEntityAuditRepository 
and comment the HBaseBasedAuditoryRepository -->
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.service\.InMemoryEntityAuditRepository.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.service\.NoopEntityAuditRepository.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.service\.KafkaNotification.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.service\.NotificationHookConsumer.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.kafka.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.webapp.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.web.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.notification.hook.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.notification.entity.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.notification.NotificationHookConsumer.*"/>
-        <context:exclude-filter type="regex" 
expression="org\.apache\.atlas\.ha.*"/>
-    </context:component-scan>
-</beans>

Reply via email to