helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: [HELIX-109] Review Helix model package, more changes
Date Fri, 30 Aug 2013 17:41:14 GMT
Updated Branches:
  refs/heads/helix-logical-model 3be06fa66 -> 02559174f


[HELIX-109] Review Helix model package, more changes


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

Branch: refs/heads/helix-logical-model
Commit: 02559174f3e6df40740d105de4d3025f2b77b927
Parents: 3be06fa
Author: zzhang <zzhang5@uci.edu>
Authored: Fri Aug 30 10:41:05 2013 -0700
Committer: zzhang <zzhang5@uci.edu>
Committed: Fri Aug 30 10:41:05 2013 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/helix/api/Id.java  | 12 +++
 .../org/apache/helix/model/CurrentState.java    |  8 ++
 .../org/apache/helix/model/ExternalView.java    |  8 ++
 .../java/org/apache/helix/model/IdealState.java |  8 ++
 .../org/apache/helix/model/InstanceConfig.java  |  8 ++
 .../org/apache/helix/model/LiveInstance.java    |  8 ++
 .../model/builder/ExternalViewBuilder.java      | 24 ++++++
 .../test/java/org/apache/helix/api/TestId.java  | 77 ++++++++++++++++++++
 8 files changed, 153 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/main/java/org/apache/helix/api/Id.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/Id.java b/helix-core/src/main/java/org/apache/helix/api/Id.java
index 338ad11..7024d22 100644
--- a/helix-core/src/main/java/org/apache/helix/api/Id.java
+++ b/helix-core/src/main/java/org/apache/helix/api/Id.java
@@ -54,6 +54,18 @@ public abstract class Id implements Comparable<Id> {
   }
 
   /**
+   * Get a concrete cluster id for a string name
+   * @param clusterId string cluter identifier
+   * @return ClusterId
+   */
+  public static ClusterId cluster(String clusterId) {
+    if (clusterId == null) {
+      return null;
+    }
+    return new ClusterId(clusterId);
+  }
+
+  /**
    * Get a concrete resource id for a string name
    * @param resourceId string resource identifier
    * @return ResourceId

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/main/java/org/apache/helix/model/CurrentState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/CurrentState.java b/helix-core/src/main/java/org/apache/helix/model/CurrentState.java
index 0797145..c4893d4 100644
--- a/helix-core/src/main/java/org/apache/helix/model/CurrentState.java
+++ b/helix-core/src/main/java/org/apache/helix/model/CurrentState.java
@@ -60,6 +60,14 @@ public class CurrentState extends HelixProperty {
   }
 
   /**
+   * Instantiate a current state with a resource
+   * @param resourceId identifier for the resource
+   */
+  public CurrentState(ResourceId resourceId) {
+    super(resourceId.stringify());
+  }
+
+  /**
    * Instantiate a current state with a pre-populated ZNRecord
    * @param record a ZNRecord corresponding to the current state
    */

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/ExternalView.java b/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
index ebbce23..16dba05 100644
--- a/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
+++ b/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
@@ -48,6 +48,14 @@ public class ExternalView extends HelixProperty {
   }
 
   /**
+   * Instantiate an external view with the resource it corresponds to
+   * @param resource the id of the resource
+   */
+  public ExternalView(ResourceId resource) {
+    super(new ZNRecord(resource.stringify()));
+  }
+
+  /**
    * Instantiate an external view with a pre-populated record
    * @param record ZNRecord corresponding to an external view
    */

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/main/java/org/apache/helix/model/IdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/IdealState.java b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
index fcadaf3..ded32c7 100644
--- a/helix-core/src/main/java/org/apache/helix/model/IdealState.java
+++ b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
@@ -105,6 +105,14 @@ public class IdealState extends HelixProperty {
   }
 
   /**
+   * Instantiate an ideal state for a resource
+   * @param resourceId the id of the resource
+   */
+  public IdealState(ResourceId resourceId) {
+    super(resourceId.stringify());
+  }
+
+  /**
    * Instantiate an ideal state from a record
    * @param record ZNRecord corresponding to an ideal state
    */

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
index 032e5c2..2dd2c4b 100644
--- a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
@@ -58,6 +58,14 @@ public class InstanceConfig extends HelixProperty {
   }
 
   /**
+   * Instantiate for a specific instance
+   * @param participantId the instance identifier
+   */
+  public InstanceConfig(ParticipantId participantId) {
+    super(participantId.stringify());
+  }
+
+  /**
    * Instantiate with a pre-populated record
    * @param record a ZNRecord corresponding to an instance configuration
    */

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/LiveInstance.java b/helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
index 4e0724a..8a4b49b 100644
--- a/helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
+++ b/helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
@@ -53,6 +53,14 @@ public class LiveInstance extends HelixProperty {
   }
 
   /**
+   * Instantiate with an participant identifier
+   * @param id participant identifier
+   */
+  public LiveInstance(ParticipantId id) {
+    super(id.stringify());
+  }
+
+  /**
    * Instantiate with a pre-populated record
    * @param record ZNRecord corresponding to a live instance
    */

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/main/java/org/apache/helix/model/builder/ExternalViewBuilder.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/builder/ExternalViewBuilder.java
b/helix-core/src/main/java/org/apache/helix/model/builder/ExternalViewBuilder.java
new file mode 100644
index 0000000..5fe099f
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/builder/ExternalViewBuilder.java
@@ -0,0 +1,24 @@
+package org.apache.helix.model.builder;
+
+/*
+ * 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.
+ */
+
+public class ExternalViewBuilder {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02559174/helix-core/src/test/java/org/apache/helix/api/TestId.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/api/TestId.java b/helix-core/src/test/java/org/apache/helix/api/TestId.java
new file mode 100644
index 0000000..05da8a3
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/api/TestId.java
@@ -0,0 +1,77 @@
+package org.apache.helix.api;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestId {
+  /**
+   * Make sure that a partition serializes and deserializes properly
+   */
+  @Test
+  public void testPartitionId() {
+    final String partitionName = "Resource_3";
+    final String resourceName = "Resource";
+    final String partitionSuffix = "3";
+    PartitionId partitionId = Id.partition(partitionName);
+    Assert.assertEquals(partitionId.stringify(), partitionName);
+    PartitionId partitionId2 = Id.partition(Id.resource(resourceName), partitionSuffix);
+    Assert.assertEquals(partitionId2.stringify(), partitionName);
+    Assert.assertEquals(partitionId, partitionId2);
+    Assert.assertEquals(partitionId.toString(), partitionId2.toString());
+  }
+
+  /**
+   * Check that PartitionId doesn't need to be of the form resource_partition for compatibility
+   */
+  @Test
+  public void testPartitionIdCompatibility() {
+    final String partitionName = "Resource--3";
+    PartitionId partitionId = Id.partition(partitionName);
+    Assert.assertEquals(partitionId.stringify(), partitionName);
+  }
+
+  /**
+   * Check that ids can be converted back and forth between strings and concrete classes
+   */
+  @Test
+  public void basicIdTest() {
+    final String resourceName = "Resource";
+    final String clusterName = "Cluster";
+    final String participantName = "Participant";
+    final String sessionName = "Session";
+    final String processName = "Process";
+    final String stateModelName = "StateModel";
+    final String messageName = "Message";
+    Assert.assertEquals(Id.resource(resourceName).stringify(), resourceName);
+    Assert.assertEquals(Id.cluster(clusterName).stringify(), clusterName);
+    Assert.assertEquals(Id.participant(participantName).stringify(), participantName);
+    Assert.assertEquals(Id.session(sessionName).stringify(), sessionName);
+    Assert.assertEquals(Id.process(processName).stringify(), processName);
+    Assert.assertEquals(Id.stateModelDef(stateModelName).stringify(), stateModelName);
+    Assert.assertEquals(Id.message(messageName).stringify(), messageName);
+  }
+
+  /**
+   * Check that equality with string works
+   */
+  @Test
+  public void testStringEquality() {
+    final String resourceName = "Resource";
+    Assert.assertTrue(Id.resource(resourceName).equals(resourceName));
+  }
+
+  /**
+   * Ensure that trying to create an id with null yields null
+   */
+  @Test
+  public void testNull() {
+    Assert.assertNull(Id.cluster(null));
+    Assert.assertNull(Id.resource(null));
+    Assert.assertNull(Id.partition(null));
+    Assert.assertNull(Id.participant(null));
+    Assert.assertNull(Id.session(null));
+    Assert.assertNull(Id.process(null));
+    Assert.assertNull(Id.stateModelDef(null));
+    Assert.assertNull(Id.message(null));
+  }
+}


Mime
View raw message