dubeejw commented on a change in pull request #2218: Port Controller from Spray 
to Akka
URL: 
https://github.com/apache/incubator-openwhisk/pull/2218#discussion_r127730619
 
 

 ##########
 File path: core/controller/src/main/scala/whisk/core/controller/API.scala
 ##########
 @@ -0,0 +1,277 @@
+/*
+ * Copyright 2015-2016 IBM Corporation
+ *
+ * Licensed 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 whisk.core.controller
+
+import akka.actor.ActorSystem
+import akka.stream.ActorMaterializer
+import akka.http.scaladsl.model.StatusCodes._
+import akka.http.scaladsl.model.Uri
+import akka.http.scaladsl.server.Directives
+import akka.http.scaladsl.server.Route
+import akka.http.scaladsl.model.headers._
+
+import spray.json._
+import spray.json.DefaultJsonProtocol._
+
+import scala.concurrent.ExecutionContext
+
+import whisk.common.TransactionId
+import whisk.core.WhiskConfig
+import whisk.core.WhiskConfig.whiskVersionBuildno
+import whisk.core.WhiskConfig.whiskVersionDate
+import whisk.core.entity.WhiskAuthStore
+import whisk.common.Logging
+import whisk.common.TransactionId
+import whisk.core.entity._
+import whisk.core.entity.types._
+import whisk.core.entitlement._
+import whisk.core.entity.ActivationId.ActivationIdGenerator
+import whisk.core.loadBalancer.LoadBalancerService
+
+/**
+  * Abstract class which provides basic Directives which are used to construct 
route structures
+  * which are common to all versions of the Rest API.
+  */
+protected[controller] class SwaggerDocs(apipath: Uri.Path, doc: 
String)(implicit actorSystem: ActorSystem)
+    extends Directives {
+
+    /** Swagger end points. */
+    protected val swaggeruipath = "docs"
+    protected val swaggerdocpath = "api-docs"
+
+    def basepath(url: Uri.Path = apipath): String = {
+        (if (url.startsWithSlash) url else Uri.Path./(url)).toString
+    }
+
+    /**
+      * Defines the routes to serve the swagger docs.
+      */
+    val swaggerRoutes: Route = {
+        pathPrefix(swaggeruipath) {
+            getFromDirectory("/swagger-ui/")
+        } ~ path(swaggeruipath) {
+            redirect(s"$swaggeruipath/index.html?url=$apiDocsUrl", 
PermanentRedirect)
+        } ~ pathPrefix(swaggerdocpath) {
+            pathEndOrSingleSlash {
+                getFromResource(doc)
+            }
+        }
+    }
+
+    /** Forces add leading slash for swagger api-doc url rewrite to work. */
+    private def apiDocsUrl = basepath(apipath / swaggerdocpath)
+}
+
+protected[controller] object RestApiCommons {
+    def requiredProperties = Map(WhiskConfig.servicePort -> 8080.toString) ++
+            WhiskConfig.whiskVersion ++
+            WhiskAuthStore.requiredProperties ++
+            WhiskEntityStore.requiredProperties ++
+            WhiskActivationStore.requiredProperties ++
+            WhiskConfig.consulServer ++
+            EntitlementProvider.requiredProperties ++
+            WhiskActionsApi.requiredProperties ++
+            Authenticate.requiredProperties ++
+            Collection.requiredProperties
+}
+
+/**
+  * A trait for wrapping routes with headers to include in response.
+  * Useful for CORS.
+  */
+protected[controller] trait RespondWithHeaders extends Directives {
+    val allowOrigin = `Access-Control-Allow-Origin`.*
+    val allowHeaders = `Access-Control-Allow-Headers`("Authorization", 
"Content-Type")
+    val sendCorsHeaders = respondWithHeaders(allowOrigin, allowHeaders)
+}
+
+class API(config: WhiskConfig, apiPath: String, apiVersion: String)(
+    implicit val activeAckTopicIndex: InstanceId,
+    implicit val actorSystem: ActorSystem,
+    implicit val logging: Logging,
+    implicit val entityStore: EntityStore,
+    implicit val entitlementProvider: EntitlementProvider,
+    implicit val activationIdFactory: ActivationIdGenerator,
+    implicit val loadBalancer: LoadBalancerService,
+    implicit val activationStore: ActivationStore,
+    implicit val consulServer: String,
+    implicit val whiskConfig: WhiskConfig)
 
 Review comment:
   Since this is the way the current controller implementation is set up, I'd 
rather open an issue and remove the redundancies as part of a separate PR. 
Looks like there will have to be test updates  for both scenarios you described 
here.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to