ningyougang commented on a change in pull request #5116: URL: https://github.com/apache/openwhisk/pull/5116#discussion_r638590570
########## File path: core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/container/CreationJobManager.scala ########## @@ -0,0 +1,268 @@ +/* + * 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.scheduler.container + +import java.nio.charset.StandardCharsets +import java.util.concurrent.TimeUnit +import akka.actor.{Actor, ActorRef, ActorRefFactory, ActorSystem, Cancellable, Props} +import org.apache.openwhisk.common.{GracefulShutdown, Logging, TransactionId} +import org.apache.openwhisk.core.connector._ +import org.apache.openwhisk.core.entity._ +import org.apache.openwhisk.core.etcd.EtcdKV.ContainerKeys.inProgressContainer +import org.apache.openwhisk.core.scheduler.queue.{MemoryQueueKey, QueuePool} +import org.apache.openwhisk.core.service.{RegisterData, UnregisterData} +import org.apache.openwhisk.core.ConfigKeys +import pureconfig.loadConfigOrThrow + +import scala.collection.concurrent.TrieMap +import scala.concurrent.duration._ +import scala.concurrent.{ExecutionContext, Future} + +sealed trait CreationJob +case class RegisterCreationJob(msg: ContainerCreationMessage) extends CreationJob +case class FinishCreationJob(ack: ContainerCreationAckMessage) extends CreationJob +case class ReschedulingCreationJob(tid: TransactionId, + creationId: CreationId, + invocationNamespace: String, + action: FullyQualifiedEntityName, + revision: DocRevision, + actionMetaData: WhiskActionMetaData, + schedulerHost: String, + rpcPort: Int, + retry: Int) + extends CreationJob { + + def toCreationMessage(sid: SchedulerInstanceId, retryCount: Int): ContainerCreationMessage = + ContainerCreationMessage( + tid, + invocationNamespace, + action, + revision, + actionMetaData, + sid, + schedulerHost, + rpcPort, + retryCount, + creationId) +} + +abstract class CreationJobState(val creationId: CreationId, + val invocationNamespace: String, + val action: FullyQualifiedEntityName, + val revision: DocRevision) +case class FailedCreationJob(override val creationId: CreationId, + override val invocationNamespace: String, + override val action: FullyQualifiedEntityName, + override val revision: DocRevision, + error: ContainerCreationError, + message: String) + extends CreationJobState(creationId, invocationNamespace, action, revision) +case class SuccessfulCreationJob(override val creationId: CreationId, + override val invocationNamespace: String, + override val action: FullyQualifiedEntityName, + override val revision: DocRevision) + extends CreationJobState(creationId, invocationNamespace, action, revision) + +case object GetPoolStatus + +case class JobEntry(action: FullyQualifiedEntityName, timer: Cancellable) + +class CreationJobManager(feedFactory: (ActorRefFactory, String, Int, Array[Byte] => Future[Unit]) => ActorRef, + schedulerInstanceId: SchedulerInstanceId, + dataManagementService: ActorRef)(implicit actorSystem: ActorSystem, logging: Logging) + extends Actor { + private implicit val ec: ExecutionContext = actorSystem.dispatcher + private val baseTimeout = loadConfigOrThrow[Int](ConfigKeys.schedulerInProgressJobRetentionSecond).seconds Review comment: For time configuration, it is better to change it to `loadConfigOrThrow[FiniteDuration]` -- 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. For queries about this service, please contact Infrastructure at: [email protected]
