Skip to content

Commit

Permalink
#521 #522 #523 deploy script and logging improvements (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieMyst authored Aug 22, 2022
1 parent db01628 commit a8eeeac
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ val scribeV = "3.7.1"
name := "aqua-hll"

val commons = Seq(
baseAquaVersion := "0.7.4",
baseAquaVersion := "0.7.5",
version := baseAquaVersion.value + "-" + sys.env.getOrElse("BUILD_NUMBER", "SNAPSHOT"),
scalaVersion := dottyVersion,
libraryDependencies ++= Seq(
Expand Down
7 changes: 4 additions & 3 deletions cli/.js/src/main/scala/aqua/builder/Console.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import aqua.io.OutputPrinter
import aqua.js.{CallJsFunction, FluencePeer, ServiceHandler}
import aqua.types.ScalarType
import cats.data.NonEmptyList
import scribe.Logging

import scala.scalajs.js
import scala.scalajs.js.JSON

private case class Console(serviceId: String, functions: NonEmptyList[AquaFunction])
extends Service(serviceId, functions)

object Console {
object Console extends Logging {

private def printFunction(funcName: String) = new AquaFunction {
override def fnName: String = funcName

def handler: ServiceHandler = { varArgs =>
js.typeOf(varArgs(0)) match {
case "string" | "number" | "boolean" => OutputPrinter.print(varArgs(0).toString)
case _ => OutputPrinter.print(JSON.stringify(varArgs(0), space = 2))
case "string" | "number" | "boolean" => logger.info(varArgs(0).toString)
case _ => logger.info(JSON.stringify(varArgs(0), space = 2))
}
js.Promise.resolve(Service.emptyObject)
}
Expand Down
48 changes: 48 additions & 0 deletions cli/.js/src/main/scala/aqua/builder/DeployHelper.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package aqua.builder

import aqua.backend.*
import aqua.ipfs.js.IpfsApi
import aqua.js.{CallJsFunction, FluencePeer, ServiceHandler}
import aqua.types.ScalarType
import cats.data.NonEmptyList
import scribe.Logging

import scala.scalajs.js

object DeployHelper extends Logging {

private val CreateResult = "create_result"

private def createResult(funcName: String): AquaFunction = new AquaFunction {
override def fnName: String = funcName

override def handler: ServiceHandler = args => {
val bid = args(0)
val sid = args(1)
js.Promise.resolve(js.Dynamic.literal(blueprint_id = bid, service_id = sid))
}

def arrow: ArrowTypeDef = ArrowTypeDef(
LabeledProductTypeDef(
("bid", ScalarTypeDef.fromScalar(ScalarType.string)) :: (
"sid",
ScalarTypeDef.fromScalar(ScalarType.string)
) :: Nil
),
UnlabeledProductTypeDef(
StructTypeDef(
"DeployResult",
Map(
"blueprint_id" -> ScalarTypeDef.fromScalar(ScalarType.string),
"service_id" -> ScalarTypeDef.fromScalar(ScalarType.string)
)
) :: Nil
)
)
}

def apply(serviceId: String = "deploy_helper"): Service = {
val funcs = NonEmptyList.one(createResult(CreateResult))
Service(serviceId, funcs)
}
}
6 changes: 4 additions & 2 deletions cli/.js/src/main/scala/aqua/builder/IPFSUploader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import scala.scalajs.js

object IPFSUploader extends Logging {

private val UploadFile = "uploadFile"

private def uploadFunc(funcName: String): AquaFunction = new AquaFunction {
override def fnName: String = funcName

Expand Down Expand Up @@ -46,8 +48,8 @@ object IPFSUploader extends Logging {
)
}

def apply(serviceId: String, fnName: String): Service = {
val funcs = NonEmptyList.one(uploadFunc(fnName))
def apply(serviceId: String): Service = {
val funcs = NonEmptyList.one(uploadFunc(UploadFile))
Service(serviceId, funcs)
}
}
2 changes: 1 addition & 1 deletion cli/.js/src/main/scala/aqua/run/RunCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object RunCommand extends Logging {
}

private val builtinServices =
aqua.builder.Console() :: aqua.builder.IPFSUploader("ipfs", "uploadFile") :: Nil
aqua.builder.Console() :: aqua.builder.IPFSUploader("ipfs") :: aqua.builder.DeployHelper() :: Nil

/**
* Executes a function with the specified settings
Expand Down
8 changes: 5 additions & 3 deletions cli/src/main/scala/aqua/FluenceOpts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ object LogLevels {
.map(validNel)
.getOrElse(
invalidNel(
s"Unknown log-level '$s'. Please use one of these: 'all', 'trace', 'debug', 'info', 'warn', 'error', 'off'"
s"Invalid log-level '$s'. ${FluenceOpts.logHelpMessage}"
)
)
}

lazy val error =
"Invalid log-level format. Must be: '<log-level>' or 'compiler=<log-level>,fluencejs=<log-level>,aquavm=<log-level>', where <log-level> is one of these strings: 'all', 'trace', 'debug', 'info', 'warn', 'error', 'off'"
s"Invalid log-level format. ${FluenceOpts.logHelpMessage}"

private def fromStrings(
name: String,
Expand Down Expand Up @@ -126,8 +126,10 @@ object FluenceOpts {
.map(_ => true)
.withDefault(false)

val logHelpMessage = "Format: '<level> OR <segment>=<level>[,]', where <level> is one of these strings: 'all', 'trace', 'debug', 'info', 'warn', 'error', 'off'. <segment> can be 'compiler', 'fluencejs' or 'aquavm'"

val logLevelOpt: Opts[LogLevels] =
Opts.option[String]("log-level", help = "Set log level").mapValidated {
Opts.option[String]("log-level", help = s"Set log level. $logHelpMessage").mapValidated {
str =>
LogLevels.fromString(str)
}.withDefault(LogLevels())
Expand Down
43 changes: 20 additions & 23 deletions npm/aqua/dist.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ data ModuleConf:
mem_pages_count: ?u32
max_heap_size: ?string

service OpC("op"):
array_length(arr: []ModuleConf) -> u32

data DeployResult:
blueprint_id: string
service_id: string

service DeployHelper("deploy_helper"):
create_result(bid: string, sid: string) -> DeployResult

data ServiceConf:
modules: []ModuleConf

Expand All @@ -33,51 +43,38 @@ func flattenS(input: []string) -> ?[]string:
res <<- input
<- res

func deploy(serviceName: string, serviceConf: ServiceConf) -> string:
func deploy(serviceName: string, serviceConf: ServiceConf) -> DeployResult:

on ON_PEER:
multiaddr <- Ipfs.get_external_api_multiaddr()

-- Console.print("BEFORE THAT")
mod_hashes: *string
for m <- serviceConf.modules:
for m <- serviceConf.modules par:
-- TODO check for cache
Console.print("Going to upload a module...")
Console.print(Op.concat_strings("Going to upload a module: ", m.name))
uploadRes <- LocalIpfs.uploadFile(m.path, multiaddr)
cid = uploadRes.cid
-- Console.print(cid)
Console.print(Op.concat_strings(Op.concat_strings("Module '", m.name), "' was uploaded"))

on ON_PEER:
hostRes <- Ipfs.get(cid)

-- Console.print(hostRes.path)
-- on ON_PEER:

conf <- Dist.make_module_config(m.name, m.mem_pages_count, m.max_heap_size, m.logger_enabled, m.preopened_files, m.envs, m.mapped_dirs, m.mounted_binaries, m.logging_mask)

-- Console.print("Created config")

-- on ON_PEER:

mod <- Dist.add_module_from_vault(hostRes.path, conf)

mod_hashes <- Op.concat_strings("hash:", mod)

join mod_hashes[OpC.array_length(serviceConf.modules) - 1]

Console.print("Now time to make a blueprint...")
on ON_PEER:

blueprint <- Dist.make_blueprint(serviceName, mod_hashes)

--Console.print("Got blueprint")
--on ON_PEER:
blueprint_id <- Dist.add_blueprint(blueprint)

blueprint_id <- Dist.add_blueprint(blueprint)
service_id <- Srv.create(blueprint_id)

Console.print("Blueprint id:")
Console.print(blueprint_id)
Console.print("And your service id is:")

<- service_id
res <- DeployHelper.create_result(blueprint_id, service_id)
<- res

func remove(service_id: string):
on ON_PEER:
Expand Down
6 changes: 3 additions & 3 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"build": "tsc"
},
"dependencies": {
"@fluencelabs/aqua-ipfs": "0.5.2",
"@fluencelabs/aqua-lib": "0.5.1",
"@fluencelabs/fluence": "0.23.3",
"@fluencelabs/aqua-ipfs": "0.5.5",
"@fluencelabs/aqua-lib": "0.5.2",
"@fluencelabs/fluence": "0.23.4",
"@fluencelabs/fluence-network-environment": "1.0.13",
"ipfs-http-client": "50.1.2"
},
Expand Down

0 comments on commit a8eeeac

Please sign in to comment.