You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by st...@apache.org on 2016/09/12 15:11:53 UTC

incubator-s2graph git commit: [S2GRAPH-12]: Add Label Name Swap Feature

Repository: incubator-s2graph
Updated Branches:
  refs/heads/master 69c18afd2 -> 56351af5f


[S2GRAPH-12]: Add Label Name Swap Feature

JIRA:
    [S2GRAPH-12] https://issues.apache.org/jira/browse/S2GRAPH-12

Pull Request:
    Closes #79

Authors
    Hyunsung Jo: hyunsung.jo@gmail.com


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

Branch: refs/heads/master
Commit: 56351af5f24a8ede85c37907323d637d05632576
Parents: 69c18af
Author: DO YUNG YOON <st...@apache.org>
Authored: Tue Sep 13 00:12:16 2016 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Tue Sep 13 00:12:16 2016 +0900

----------------------------------------------------------------------
 CHANGES                                         |  5 ++-
 .../org/apache/s2graph/core/Management.scala    | 31 ++++++++++++-----
 .../apache/s2graph/core/ManagementTest.scala    | 36 ++++++++++++++++++++
 .../rest/play/controllers/AdminController.scala | 24 +++++++++++--
 s2rest_play/conf/routes                         |  3 +-
 5 files changed, 85 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/56351af5/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index dbdb9e3..96744d0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -19,7 +19,7 @@
 
  Change Log
 
-Release 0.12.1 - unreleased
+Release 0.1.0 - unreleased
 
   NEW FEATURES
     
@@ -40,6 +40,9 @@ Release 0.12.1 - unreleased
     S2GRAPH-60: Add divide operation to scorePropagateOp.
 		(Contributed by Junki Kim<wi...@gmail.com>, committed by DOYUNG YOON).
 
+    S2GRAPH-12: Add Label Name Swap Feature.
+		(Contributed by Hyunsung Jo<hy...@gmail.com>, committed by DOYUNG YOON).
+
   IMPROVEMENT
 
     S2GRAPH-14: Abstract HBase specific methods in Management and Label (Committed by DOYUNG YOON).

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/56351af5/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/Management.scala b/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
index 2c77d4b..5f5388b 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
@@ -270,22 +270,35 @@ object Management extends JSONParser {
     props
   }
 
-
   /**
    * update label name.
    */
   def updateLabelName(oldLabelName: String, newLabelName: String) = {
-    for {
-      old <- Label.findByName(oldLabelName)
-    } {
-      Label.findByName(newLabelName) match {
-        case None =>
-          Label.updateName(oldLabelName, newLabelName)
-        case Some(_) =>
-        //          throw new RuntimeException(s"$newLabelName already exist")
+    Model withTx { implicit session =>
+      for {
+        old <- Label.findByName(oldLabelName, useCache = false)
+      } {
+        Label.findByName(newLabelName, useCache = false) match {
+          case None =>
+            Label.updateName(oldLabelName, newLabelName)
+          case Some(_) =>
+            throw new RuntimeException(s"$newLabelName already exist")
+        }
       }
     }
   }
+
+  /**
+   * swap label names.
+   */
+  def swapLabelNames(leftLabel: String, rightLabel: String) = {
+    Model withTx { implicit session =>
+      val tempLabel = "_" + leftLabel + "_"
+      Label.updateName(leftLabel, tempLabel)
+      Label.updateName(rightLabel, leftLabel)
+      Label.updateName(tempLabel, rightLabel)
+    }
+  }
 }
 
 class Management(graph: Graph) {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/56351af5/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala
new file mode 100644
index 0000000..e21f0e7
--- /dev/null
+++ b/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala
@@ -0,0 +1,36 @@
+/*
+ * 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.s2graph.core
+
+import org.apache.s2graph.core.Integrate.IntegrateCommon
+import org.apache.s2graph.core.mysqls.Label
+
+class ManagementTest extends IntegrateCommon {
+  test("swap label test") {
+    val labelLeft = TestUtil.testLabelName
+    val labelRight = TestUtil.testLabelName2
+    Management.swapLabelNames(labelLeft, labelRight)
+    Label.findByName(labelLeft, false).get.schemaVersion should be("v3")
+    Label.findByName(labelRight, false).get.schemaVersion should be("v4")
+    Management.swapLabelNames(labelLeft, labelRight)
+    Label.findByName(labelLeft, false).get.schemaVersion should be("v4")
+    Label.findByName(labelRight, false).get.schemaVersion should be("v3")
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/56351af5/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
----------------------------------------------------------------------
diff --git a/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala b/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
index 7f4429b..36610e0 100644
--- a/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
+++ b/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
@@ -345,7 +345,7 @@ object AdminController extends Controller {
    */
   def copyLabel(oldLabelName: String, newLabelName: String) = Action { request =>
     val copyTry = management.copyLabel(oldLabelName, newLabelName, Some(newLabelName))
-    tryResponse(copyTry)(_.label + "created")
+    tryResponse(copyTry)(_.label + " created")
   }
 
   /**
@@ -356,10 +356,10 @@ object AdminController extends Controller {
    */
   def renameLabel(oldLabelName: String, newLabelName: String) = Action { request =>
     Label.findByName(oldLabelName) match {
-      case None => NotFound.as(applicationJsonHeader)
+      case None => NotFound.as(s"Label $oldLabelName not found.")
       case Some(label) =>
         Management.updateLabelName(oldLabelName, newLabelName)
-        ok(s"Label was updated")
+        ok(s"Label was updated.")
     }
   }
 
@@ -374,6 +374,24 @@ object AdminController extends Controller {
     tryResponse(updateTry)(_.toString + " label(s) updated.")
   }
 
+  /**
+   * swap two label names
+   * @param leftLabelName
+   * @param rightLabelName
+   * @return
+   */
+  def swapLabels(leftLabelName: String, rightLabelName: String) = Action { request =>
+    val left = Label.findByName(leftLabelName, useCache = false)
+    val right = Label.findByName(rightLabelName, useCache = false)
+    // verify same schema
+
+    (left, right) match {
+      case (Some(l), Some(r)) =>
+        Management.swapLabelNames(leftLabelName, rightLabelName)
+        ok(s"Labels were swapped.")
+      case _ => notFound(s"Labels ${leftLabelName} or ${rightLabelName} not found.")
+    }
+  }
 
   case class HTableParams(cluster: String, hTableName: String,
     preSplitSize: Int, hTableTTL: Option[Int], compressionAlgorithm: Option[String]) {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/56351af5/s2rest_play/conf/routes
----------------------------------------------------------------------
diff --git a/s2rest_play/conf/routes b/s2rest_play/conf/routes
index 000793e..ee49c69 100644
--- a/s2rest_play/conf/routes
+++ b/s2rest_play/conf/routes
@@ -96,6 +96,7 @@ POST        /graphs/createHTable                                          org.ap
 GET         /admin/labels/:serviceName                                    org.apache.s2graph.rest.play.controllers.AdminController.getLabels(serviceName)
 POST        /graphs/copyLabel/:oldLabelName/:newLabelName                 org.apache.s2graph.rest.play.controllers.AdminController.copyLabel(oldLabelName, newLabelName)
 POST        /graphs/renameLabel/:oldLabelName/:newLabelName               org.apache.s2graph.rest.play.controllers.AdminController.renameLabel(oldLabelName, newLabelName)
+POST        /graphs/swapLabels/:leftLabelName/:rightLabelName             org.apache.s2graph.rest.play.controllers.AdminController.swapLabels(leftLabelName, rightLabelName)
 POST        /graphs/updateHTable/:labelName/:newHTableName                org.apache.s2graph.rest.play.controllers.AdminController.updateHTable(labelName, newHTableName)
 PUT         /graphs/loadCache                                             org.apache.s2graph.rest.play.controllers.AdminController.loadCache()
 
@@ -123,4 +124,4 @@ GET         /images/*file                                                 contro
 GET         /javascripts/*file                                            controllers.Assets.at(path="/public/javascripts", file)
 GET         /stylesheets/*file                                            controllers.Assets.at(path="/public/stylesheets", file)
 GET         /font-awesome-4.1.0/*file                                     controllers.Assets.at(path="/public/font-awesome-4.1.0", file)
-GET         /swagger/*file                                                controllers.Assets.at(path="/public/swagger-ui", file)
\ No newline at end of file
+GET         /swagger/*file                                                controllers.Assets.at(path="/public/swagger-ui", file)