openwhisk-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [openwhisk] style95 commented on a change in pull request #4686: A playground UI intended for the standalone controller
Date Mon, 21 Oct 2019 06:56:12 GMT
style95 commented on a change in pull request #4686: A playground UI intended for the standalone
controller
URL: https://github.com/apache/openwhisk/pull/4686#discussion_r336859487
 
 

 ##########
 File path: core/standalone/src/main/scala/org/apache/openwhisk/standalone/PlaygroundLauncher.scala
 ##########
 @@ -0,0 +1,127 @@
+/*
+ * 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.standalone
+
+import java.nio.charset.StandardCharsets.UTF_8
+
+import akka.actor.ActorSystem
+import akka.http.scaladsl.model.{ContentType, HttpCharsets, HttpEntity, MediaTypes, StatusCodes}
+import akka.http.scaladsl.server.Route
+import akka.http.scaladsl.server.directives.FileAndResourceDirectives.ResourceFile
+import akka.stream.ActorMaterializer
+import akka.stream.scaladsl.{Sink, Source}
+import org.apache.commons.io.IOUtils
+import org.apache.commons.lang3.SystemUtils
+import org.apache.openwhisk.common.{Logging, TransactionId}
+import org.apache.openwhisk.core.ExecManifestSupport
+import org.apache.openwhisk.http.BasicHttpService
+import pureconfig.loadConfigOrThrow
+
+import scala.concurrent.duration._
+import scala.concurrent.{Await, ExecutionContext}
+import scala.util.{Failure, Success, Try}
+import scala.sys.process._
+
+class PlaygroundLauncher(host: String, controllerPort: Int, pgPort: Int, authKey: String,
devMode: Boolean)(
+  implicit logging: Logging,
+  ec: ExecutionContext,
+  actorSystem: ActorSystem,
+  materializer: ActorMaterializer,
+  tid: TransactionId) {
+  private val interface = loadConfigOrThrow[String]("whisk.controller.interface")
+  private val jsFileName = "playgroundFunctions.js"
+  private val jsContentType = ContentType(MediaTypes.`application/javascript`, HttpCharsets.`UTF-8`)
+
+  private val uiPath = {
+    //Depending on fact the run is done from within IDE or from terminal the classpath prefix
needs to be adapted
+    val res = getClass.getResource(s"/playground/ui/$jsFileName")
+    Try(ResourceFile(res)) match {
+      case Success(_) => "playground/ui"
+      case Failure(_) => "BOOT-INF/classes/playground/ui"
+    }
+  }
+
+  private val jsFileContent = {
+    val js = resourceToString(jsFileName, "ui")
+    val content = js.replace("window.APIHOST='http://localhost:3233'", s"window.APIHOST='http://$host:$controllerPort'")
+    content.getBytes(UTF_8)
+  }
+
+  private val pg = "playground"
+  private val pgUrl = s"http://${StandaloneDockerSupport.getLocalHostName()}:$pgPort/$pg"
+
+  private val wsk = new Wsk(host, controllerPort, authKey)
+
+  def run(): ServiceContainer = {
+    BasicHttpService.startHttpService(PlaygroundService.route, pgPort, None, interface)(actorSystem,
materializer)
+    ServiceContainer(pgPort, pgUrl, "Playground")
+  }
+
+  def install(): Unit = {
+    val actions = List("delete", "fetch", "run", "userpackage")
+    val f = Source(actions)
+      .mapAsync(1) { name =>
+        val actionName = s"playground-$name"
+        val js = resourceToString(s"playground-$name.js", "actions")
+        val r = wsk.updatePgAction(actionName, js)
+        r.foreach(_ => logging.info(this, s"Installed action $actionName"))
+        r
+      }
+      .runWith(Sink.ignore)
+    Await.result(f, 5.minutes)
+    Try {
+      if (!devMode) {
+        prePullDefaultImages()
+      }
+      launchBrowser(pgUrl)
+    }.failed.foreach(t => logging.warn(this, "Failed to launch browser " + t))
+  }
+
+  private def launchBrowser(url: String): Unit = {
 
 Review comment:
   Love this thoughtful behavior. 👍 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message