helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kisho...@apache.org
Subject git commit: HELIX-70 Making Helix OSGi ready
Date Thu, 08 Aug 2013 07:42:27 GMT
Updated Branches:
  refs/heads/master d1808bc6f -> e67a66ef1


HELIX-70 Making Helix OSGi ready


Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/e67a66ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/e67a66ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/e67a66ef

Branch: refs/heads/master
Commit: e67a66ef10b8cb3a811187b76c421f1ab673a226
Parents: d1808bc
Author: Kishore Gopalakrishna <g.kishore@gmail.com>
Authored: Thu Aug 8 00:42:07 2013 -0700
Committer: Kishore Gopalakrishna <g.kishore@gmail.com>
Committed: Thu Aug 8 00:42:07 2013 -0700

----------------------------------------------------------------------
 helix-admin-webapp/pom.xml                      |  13 ++-
 helix-agent/pom.xml                             |  10 ++
 helix-core/pom.xml                              |  27 ++++-
 .../stages/RebalanceIdealStateStage.java        |  21 +++-
 .../manager/zk/ZkCacheBaseDataAccessor.java     |   2 +-
 .../java/org/apache/helix/util/PathUtils.java   | 103 +++++++++++++++++++
 pom.xml                                         |  46 +++++++++
 recipes/distributed-lock-manager/pom.xml        |  11 +-
 recipes/rabbitmq-consumer-group/pom.xml         |  11 +-
 recipes/rsync-replicated-file-system/pom.xml    |  11 +-
 recipes/service-discovery/pom.xml               |  11 +-
 recipes/task-execution/pom.xml                  |   2 +-
 12 files changed, 258 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/helix-admin-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/pom.xml b/helix-admin-webapp/pom.xml
index 0b07881..544a513 100644
--- a/helix-admin-webapp/pom.xml
+++ b/helix-admin-webapp/pom.xml
@@ -26,9 +26,20 @@ under the License.
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>helix-admin-webapp</artifactId>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <name>Apache Helix :: Admin Webapp</name>
 
+  <properties>
+    <osgi.import>
+      org.apache.helix*,
+      org.codehaus.jackson*,
+      org.apache.commons.cli*,
+      org.apache.log4j,
+      org.restlet*,
+      *
+    </osgi.import>
+    <osgi.export>org.apache.helix.webapp*;version="${project.version};-noimport:=true</osgi.export>
+  </properties>
 
   <dependencies>
     <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/helix-agent/pom.xml
----------------------------------------------------------------------
diff --git a/helix-agent/pom.xml b/helix-agent/pom.xml
index 441225f..6d690e5 100644
--- a/helix-agent/pom.xml
+++ b/helix-agent/pom.xml
@@ -25,8 +25,18 @@ under the License.
     <version>0.6.2-incubating-SNAPSHOT</version>
   </parent>
   <artifactId>helix-agent</artifactId>
+  <packaging>bundle</packaging>
   <name>Apache Helix :: HelixAgent</name>
 
+  <properties>
+    <osgi.import>
+      org.apache.helix*,
+      org.apache.commons.cli;version="[1.2,2)",
+      org.apache.log4j,
+      *
+    </osgi.import>
+    <osgi.export>org.apache.helix.agent*;version="${project.version};-noimport:=true</osgi.export>
+  </properties>
 
   <dependencies>
     <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/helix-core/pom.xml
----------------------------------------------------------------------
diff --git a/helix-core/pom.xml b/helix-core/pom.xml
index bb8ed90..5b45901 100644
--- a/helix-core/pom.xml
+++ b/helix-core/pom.xml
@@ -26,11 +26,34 @@ under the License.
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>helix-core</artifactId>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
 
   <name>Apache Helix :: Core</name>
 
-
+  <properties>
+    <osgi.import>
+      javax.management*,
+      javax.xml.bind*,
+      org.I0Itec.zkclient*,
+      org.apache.commons.cli*;version="[1.2,2)",
+      org.apache.commons.io*;version="[1.4,2)",
+      org.apache.commons.math*;version="[2.1,3)",
+      org.apache.log4j*;version="[1.2,2)",
+      org.apache.jute*;resolution:=optional,
+      org.apache.zookeeper.server.persistence*;resolution:=optional,
+      org.apache.zookeeper.server.util*;resolution:=optional,
+      org.apache.zookeeper.txn*;resolution:=optional,
+      org.apache.zookeeper*;version="[3.3,4)",
+      org.codehaus.jackson*;version="[1.8,2)",
+      org.josql*;version="[1.5,2)",
+      org.restlet;version="[1.1,2)",
+      *
+    </osgi.import>
+    <osgi.ignore>
+      org.apache.helix.tools*
+    </osgi.ignore>
+    <osgi.export>org.apache.helix*;version="${project.version};-noimport:=true</osgi.export>
+  </properties>
 
   <dependencies>
     <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java
b/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java
index 9e772ff..7ba0dbe 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java
@@ -60,7 +60,7 @@ public class RebalanceIdealStateStage extends AbstractBaseStage
         LOG.info("resource " + resourceName + " use idealStateRebalancer " + rebalancerClassName);
         try
         {
-          Rebalancer balancer = (Rebalancer) (Class.forName(rebalancerClassName).newInstance());
+          Rebalancer balancer = (Rebalancer) (loadClass(rebalancerClassName).newInstance());
           balancer.init(manager);
           IdealState newIdealState = balancer.computeNewIdealState(resourceName, idealStateMap.get(resourceName),
currentStateOutput, cache);
           updatedIdealStates.put(resourceName, newIdealState);
@@ -76,4 +76,23 @@ public class RebalanceIdealStateStage extends AbstractBaseStage
       cache.getIdealStates().putAll(updatedIdealStates);
     }
   }
+
+  /**
+   * Attempts to load the class and delegates to TCCL if class is not found.
+   * Note: The approach is used as a last resort for environments like OSGi.
+   * @param className
+   * @return
+   * @throws ClassNotFoundException
+   */
+  private Class loadClass(String className) throws ClassNotFoundException {
+    try {
+      return getClass().getClassLoader().loadClass(className);
+    } catch (ClassNotFoundException ex) {
+      if (Thread.currentThread().getContextClassLoader() != null) {
+        return Thread.currentThread().getContextClassLoader().loadClass(className);
+      } else {
+        throw ex;
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
index 9eb926d..869871c 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
@@ -40,9 +40,9 @@ import org.apache.helix.manager.zk.ZkBaseDataAccessor.RetCode;
 import org.apache.helix.store.HelixPropertyListener;
 import org.apache.helix.store.HelixPropertyStore;
 import org.apache.helix.store.zk.ZNode;
+import org.apache.helix.util.PathUtils;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.common.PathUtils;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.DataTree;
 

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/helix-core/src/main/java/org/apache/helix/util/PathUtils.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/util/PathUtils.java b/helix-core/src/main/java/org/apache/helix/util/PathUtils.java
new file mode 100644
index 0000000..85d2947
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/util/PathUtils.java
@@ -0,0 +1,103 @@
+ /**
+ * 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.helix.util;
+
+
+/**
+ * Path related utilities
+ */    
+public class PathUtils {
+	
+	/** validate the provided znode path string
+	 * @param path znode path string
+	 * @param isSequential if the path is being created
+	 * with a sequential flag
+	 * @throws IllegalArgumentException if the path is invalid
+	 */
+	public static void validatePath(String path, boolean isSequential) 
+		throws IllegalArgumentException {
+		validatePath(isSequential? path + "1": path);
+	}
+	
+    /**
+     * Validate the provided znode path string
+     * @param path znode path string
+     * @throws IllegalArgumentException if the path is invalid
+     */
+    public static void validatePath(String path) throws IllegalArgumentException {
+        if (path == null) {
+            throw new IllegalArgumentException("Path cannot be null");
+        }
+        if (path.length() == 0) {
+            throw new IllegalArgumentException("Path length must be > 0");
+        }
+        if (path.charAt(0) != '/') {
+            throw new IllegalArgumentException(
+                         "Path must start with / character");
+        }
+        if (path.length() == 1) { // done checking - it's the root
+            return;
+        }
+        if (path.charAt(path.length() - 1) == '/') {
+            throw new IllegalArgumentException(
+                         "Path must not end with / character");
+        }
+
+        String reason = null;
+        char lastc = '/';
+        char chars[] = path.toCharArray();
+        char c;
+        for (int i = 1; i < chars.length; lastc = chars[i], i++) {
+            c = chars[i];
+
+            if (c == 0) {
+                reason = "null character not allowed @" + i;
+                break;
+            } else if (c == '/' && lastc == '/') {
+                reason = "empty node name specified @" + i;
+                break;
+            } else if (c == '.' && lastc == '.') {
+                if (chars[i-2] == '/' &&
+                        ((i + 1 == chars.length)
+                                || chars[i+1] == '/')) {
+                    reason = "relative paths not allowed @" + i;
+                    break;
+                }
+            } else if (c == '.') {
+                if (chars[i-1] == '/' &&
+                        ((i + 1 == chars.length)
+                                || chars[i+1] == '/')) {
+                    reason = "relative paths not allowed @" + i;
+                    break;
+                }
+            } else if (c > '\u0000' && c <= '\u001f'
+                    || c >= '\u007f' && c <= '\u009F'
+                    || c >= '\ud800' && c <= '\uf8ff'
+                    || c >= '\ufff0' && c <= '\uffff') {
+                reason = "invalid charater @" + i;
+                break;
+            }
+        }
+
+        if (reason != null) {
+            throw new IllegalArgumentException(
+                    "Invalid path string \"" + path + "\" caused by " + reason);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4a60b72..e708034 100644
--- a/pom.xml
+++ b/pom.xml
@@ -221,6 +221,16 @@ under the License.
     <!-- for release changelog and download pages -->
     <currentRelease>0.6.1-incubating</currentRelease>
 
+    <!-- OSGi Properties -->
+    <osgi.import/>
+    <osgi.dynamic.import/>
+    <osgi.require.bundles/>
+    <osgi.export/>
+    <osgi.private/>
+    <osgi.ignore/>
+    <osgi.activator/>
+    <osgi.export.service/>
+    
     <!--Skips test in default 'mvn clean install' build command-->
     <!-- <maven.test.skip.exec>true</maven.test.skip.exec> -->
     
@@ -444,6 +454,42 @@ under the License.
         <artifactId>license-maven-plugin</artifactId>
         <version>1.3</version>
       </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
+        <inherited>true</inherited>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-Name>${project.name}</Bundle-Name>
+            <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+            <Export-Package>${osgi.export}</Export-Package>
+            <Import-Package>${osgi.import}</Import-Package>
+            <DynamicImport-Package>${osgi.dynamic.import}</DynamicImport-Package>
+            <Private-Package>${osgi.private}</Private-Package>
+            <Require-Bundle>${osgi.require.bundles}</Require-Bundle>
+            <Ignore-Package>${osgi.ignore}</Ignore-Package>
+            <Bundle-Activator>${osgi.activator}</Bundle-Activator>
+            <Export-Service>${osgi.export.service}</Export-Service>
+          </instructions>
+          <supportedProjectTypes>
+            <supportedProjectType>jar</supportedProjectType>
+            <supportedProjectType>war</supportedProjectType>
+            <supportedProjectType>bundle</supportedProjectType>
+          </supportedProjectTypes>
+          <unpackBundle>true</unpackBundle>
+        </configuration>
+        <executions>
+          <execution>
+            <id>bundle-manifest</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>manifest</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
       <!--attach source to Maven repository-->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/recipes/distributed-lock-manager/pom.xml
----------------------------------------------------------------------
diff --git a/recipes/distributed-lock-manager/pom.xml b/recipes/distributed-lock-manager/pom.xml
index a331168..0b5d1e4 100644
--- a/recipes/distributed-lock-manager/pom.xml
+++ b/recipes/distributed-lock-manager/pom.xml
@@ -27,9 +27,18 @@ under the License.
   </parent>
 
   <artifactId>distributed-lock-manager</artifactId>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <name>Apache Helix :: Recipes :: distributed lock manager</name>
 
+  <properties>
+    <osgi.import>
+      org.apache.helix*,
+      org.apache.log4j,
+      *
+    </osgi.import>
+    <osgi.export>org.apache.helix.lockmanager*;version="${project.version};-noimport:=true</osgi.export>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>org.testng</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/recipes/rabbitmq-consumer-group/pom.xml
----------------------------------------------------------------------
diff --git a/recipes/rabbitmq-consumer-group/pom.xml b/recipes/rabbitmq-consumer-group/pom.xml
index c239ac6..111c3ca 100644
--- a/recipes/rabbitmq-consumer-group/pom.xml
+++ b/recipes/rabbitmq-consumer-group/pom.xml
@@ -28,9 +28,18 @@ under the License.
   </parent>
 
   <artifactId>rabbitmq-consumer-group</artifactId>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <name>Apache Helix :: Recipes :: Rabbitmq Consumer Group</name>
 
+  <properties>
+    <osgi.import>
+      org.apache.helix*,
+      org.apache.log4j,
+      *
+    </osgi.import>
+    <osgi.export>org.apache.helix.rabbitmq*;version="${project.version};-noimport:=true</osgi.export>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>junit</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/recipes/rsync-replicated-file-system/pom.xml
----------------------------------------------------------------------
diff --git a/recipes/rsync-replicated-file-system/pom.xml b/recipes/rsync-replicated-file-system/pom.xml
index 72c5b40..3e7e08b 100644
--- a/recipes/rsync-replicated-file-system/pom.xml
+++ b/recipes/rsync-replicated-file-system/pom.xml
@@ -27,9 +27,18 @@ under the License.
   </parent>
 
   <artifactId>rsync-replicated-file-system</artifactId>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <name>Apache Helix :: Recipes :: Rsync Replicated File Store</name>
 
+  <properties>
+    <osgi.import>
+      org.apache.helix*,
+      org.apache.log4j,
+      *
+    </osgi.import>
+    <osgi.export>org.apache.helix.filestore*;version="${project.version};-noimport:=true</osgi.export>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>junit</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/recipes/service-discovery/pom.xml
----------------------------------------------------------------------
diff --git a/recipes/service-discovery/pom.xml b/recipes/service-discovery/pom.xml
index a92c0c2..e1c45e8 100644
--- a/recipes/service-discovery/pom.xml
+++ b/recipes/service-discovery/pom.xml
@@ -27,9 +27,18 @@ under the License.
   </parent>
 
   <artifactId>service-discovery</artifactId>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <name>Apache Helix :: Recipes :: service discovery</name>
 
+  <properties>
+    <osgi.import>
+      org.apache.helix*,
+      org.apache.log4j,
+      *
+    </osgi.import>
+    <osgi.export>org.apache.helix.servicediscovery*;version="${project.version};-noimport:=true</osgi.export>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>org.testng</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e67a66ef/recipes/task-execution/pom.xml
----------------------------------------------------------------------
diff --git a/recipes/task-execution/pom.xml b/recipes/task-execution/pom.xml
index 0129ce7..8f8683c 100644
--- a/recipes/task-execution/pom.xml
+++ b/recipes/task-execution/pom.xml
@@ -27,7 +27,7 @@ under the License.
   </parent>
 
   <artifactId>task-execution</artifactId>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <name>Apache Helix :: Recipes :: distributed task execution</name>
 
   <dependencies>


Mime
View raw message