JesseStutler commented on a change in pull request #5031:
URL: https://github.com/apache/openwhisk/pull/5031#discussion_r728965051



##########
File path: 
common/scala/src/main/scala/org/apache/openwhisk/core/etcd/EtcdUtils.scala
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.openwhisk.core.etcd
+
+import java.nio.charset.StandardCharsets
+
+import com.google.protobuf.ByteString
+import org.apache.openwhisk.core.ConfigKeys
+import org.apache.openwhisk.core.containerpool.ContainerId
+import org.apache.openwhisk.core.entity.SizeUnits.MB
+import org.apache.openwhisk.core.entity._
+import org.apache.openwhisk.core.entity.size._
+import pureconfig.loadConfigOrThrow
+
+import scala.language.implicitConversions
+import scala.util.Try
+
+case class EtcdConfig(hosts: String)
+
+case class EtcdException(msg: String) extends Exception(msg)
+
+/**
+ * If you import the line below, it implicitly converts ByteString type to 
Scala Type.
+ *
+ * import org.apache.openwhisk.core.etcd.EtcdType._
+ */
+object EtcdType {
+
+  implicit def stringToByteString(str: String): ByteString = 
ByteString.copyFromUtf8(str)
+
+  implicit def ByteStringToString(byteString: ByteString): String = 
byteString.toString(StandardCharsets.UTF_8)
+
+  implicit def ByteStringToInt(byteString: ByteString): Int = 
byteString.toString(StandardCharsets.UTF_8).toInt
+
+  implicit def IntToByteString(int: Int): ByteString = 
ByteString.copyFromUtf8(int.toString)
+
+  implicit def ByteStringToLong(byteString: ByteString): Long = 
byteString.toString(StandardCharsets.UTF_8).toLong
+
+  implicit def LongToByteString(long: Long): ByteString = 
ByteString.copyFromUtf8(long.toString)
+
+  implicit def ByteStringToBoolean(byteString: ByteString): Boolean =
+    byteString.toString(StandardCharsets.UTF_8).toBoolean
+
+  implicit def BooleanToByteString(bool: Boolean): ByteString = 
ByteString.copyFromUtf8(bool.toString)
+
+  implicit def ByteStringToByteSize(byteString: ByteString): ByteSize =
+    ByteSize(byteString.toString(StandardCharsets.UTF_8).toLong, MB)
+
+  implicit def ByteSizeToByteString(byteSize: ByteSize): ByteString = 
ByteString.copyFromUtf8(byteSize.toMB.toString)
+
+}
+
+object EtcdKV {
+
+  val TOP = "\ufff0"
+
+  val clusterName = loadConfigOrThrow[String](ConfigKeys.whiskClusterName)
+
+  object SchedulerKeys {
+    val prefix = s"$clusterName/scheduler"
+
+    val scheduler = s"$prefix"
+
+    /**
+     *  The keys for states of schedulers
+     */
+    def scheduler(instanceId: SchedulerInstanceId) = 
s"$prefix/${instanceId.asString}"
+
+  }
+
+  object QueueKeys {
+
+    val inProgressPrefix = s"$clusterName/in-progress"
+    val queuePrefix = s"$clusterName/queue"
+
+    /**
+     * The keys for in-progress queue
+     */
+    def inProgressQueue(invocationNamespace: String, fqn: 
FullyQualifiedEntityName) =
+      s"$inProgressPrefix/queue/$invocationNamespace/${fqn.copy(version = 
None)}"
+
+    /**
+     * The prefix key for state in the queue
+     */
+    def queuePrefix(invocationNamespace: String, fqn: 
FullyQualifiedEntityName): String =
+      s"$queuePrefix/$invocationNamespace/${fqn.copy(version = None)}"
+
+    /**
+     * The keys for state in the queue
+     *
+     * Example
+     *  - queue/invocationNs/ns/pkg/act/leader
+     *  - queue/invocationNs/ns/pkg/act/follower/scheduler1
+     *  - queue/invocationNs/ns/pkg/act/follower/scheduler2
+     *
+     */
+    def queue(invocationNamespace: String,

Review comment:
       Hi, sorry to bother you. I'm interested in openwhisk's new scheduler 
design and try to follow to do some extra customization for my idea. Now I'm 
trying to read the new scheduler's already merged code and take QueueManger 
first. I'm scala noob and new to openwhisk, when I read here, I got some 
questions:
   
https://github.com/apache/openwhisk/blob/285f9d4afcc429d63baa1943a69bb64097b059dd/core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/queue/QueueManager.scala#L447
   What does getLeaderKey's leader mean?And I have seen a lot QueueKeys.queue, 
I don't know what is queue method used for. Could you give some advice? Thanks 
a lot. :)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to