Issue Creating Kinesis Stream with Scalazon - scala

I'm following the Scalazon example at here to create a Kinesis stream. The following piece of code:
val streamListFuture = for {
s <- Kinesis.streams.list
} yield s
gives the following error:
[error] KinesisStatsWriter.scala:51: value map is not a member of object io.github.cloudify.scala.aws.kinesis.Requests.ListStreams
[error] s <- Kinesis.streams.list
If I don't use a for comprehension and call val createStream = Kinesis.streams.list, there's no error. Can't seem to figure out why.
Similarly, the following bit of code:
val createStream = for {
s <- Kinesis.streams.create(name)
} yield s
produces a similar error:
[error] KinesisStatsWriter.scala:64: value map is not a member of io.github.cloudify.scala.aws.kinesis.Requests.CreateStream
[error] s <- Kinesis.streams.create(name)
Appreciate the help!

Author here, the for-comprehension works only if you include the module that implicitly converts requests to Futures (it's called ImplicitExecution). Try adding the following import statement (looks at the sample code in the library README).
import io.github.cloudify.scala.aws.kinesis.Client.ImplicitExecution._

Related

Reactivemongo parseURI is failing when loading from config saying it can't find implicit value for parameter loader MongoConnection.ParsedURI

I am trying to use the reactivemongo driver in my play application without using the play module for reactive mongo.
So when I try and get the parsedURI from my config, I am getting the below error:
import reactivemongo.api.MongoConnection.ParsedURI
import reactivemongo.api.AsyncDriver
import com.typesafe.config.Config
val driver = new AsyncDriver(Some(config.get[Config]("mongodb")))
val parsedUri = config.get[ParsedURI]("mongodb.uri")
Error message:
could not find implicit value for parameter loader:
play.api.ConfigLoader[reactivemongo.api.MongoConnection.ParsedURI]
[error] val parsedUri = config.getParsedURI
[error] ^ [error] one error
found
My application.conf has:
mongodb {
uri = "mongodb://127.0.0.1:27017/mydb"
mongo-async-driver = ${akka}
}
ConfigLoader is a Play type class (like Reads) which tells play how to read a type from the config file.
You can find an explanation here: https://www.playframework.com/documentation/2.8.x/ScalaConfig#ConfigLoader
Generally you would define this by doing something like:
// Config
{
config {
url = "https://example.com"
}
}
// Config class
case class AConfig(url: String)
// Config Loader
implicit val configLoader: ConfigLoader[AConfig] = ConfigLoader {root => key =>
val config = root.getConfig(key)
AConfig(config.get[String]("url"))
}
// Usage
val aConfig = config.get[AConfig]("config")
In this case I would not suggest attempting to make one for ParsedURI because it is quite a complex type. Instead I would suggest doing something like:
val parsedUri: Try[ParsedURI] = MongoConnection.parseURI(config.get[String]("mongodb.uri"))

Gatling: Dynamically assemble HttpCheck for multiple Css selectors

I am working on a Gatling test framework that can be parameterized through external config objects. One use case I have is that there may be zero or more CSS selector checks that need to be saved to variables. In my config object, I've implemented that as a Map[String,(String, String)], where the key is the variable name, and the value is the 2-part css selector.
I am struggling with how to dynamically assemble the check. Here's what I got so far:
val captureMap: Map[String, (String, String)] = config.capture
httpRequestBuilder.check(
captureMap.map((mapping) => {
val varName = mapping._1
val cssSel = mapping._2
css(cssSel._1, cssSel._2).saveAs(varName)
}).toArray: _* // compilation error here
)
The error I'm getting is:
Error:(41, 10) type mismatch;
found : Array[io.gatling.core.check.CheckBuilder[io.gatling.core.check.css.CssCheckType,jodd.lagarto.dom.NodeSelector,String]]
required: Array[_ <: io.gatling.http.check.HttpCheck]
}).toArray: _*
apparently, I need to turn my CheckBuilder into a HttpCheck, so how do I do that?
Update:
I managed to get it to work by introducing a variable of type HttpCheck and returning it in the next line:
httpRequestBuilder.check(
captureMap.map((mapping) => {
val varName = mapping._1
val cssSel = mapping._2
val check:HttpCheck= css(cssSel._1, cssSel._2).saveAs(varName)
check
}).toArray: _*
)
While this works, it's ugly as hell. Can this be improved?
I had the same issue.
I had the following imports:
import io.gatling.core.Predef._
import io.gatling.http.Predef.http
I changed these imports to:
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.http.request.builder.HttpRequestBuilder.toActionBuilder
which made it work.

Unable to deserialize mleap bundle

I am getting a java.util.NoSuchElementException: None.get on the following code:
// Deserialize a directory bundle
val bundle = (for(bundleFile <- managed(BundleFile(bundle_path))) yield {
bundleFile.loadMleapBundle().get
}).opt.get
The error is on the opt.get line
An example from one of MLeap's tests deserializes a bundle this way:
val bundle = (for(bundle <- managed(BundleFile(new File(lrUri.getPath)))) yield {
bundle.loadMleapBundle().get
}).tried.get
Perhaps you should use tried instead of opt.

Elastic4s client bulk operation error

I am trying to use scala elstic4s client to index new documents into my elasticsearch cluster but I am having a compilation problem with the types. Following the documentation and the examples found in the web, the syntax looks like:
Client instantiation:
val settings = ImmutableSettings.settingsBuilder().put("cluster.name", Configuration.elasticsearchClusterName).build()
val uri = ElasticsearchClientUri("elasticsearch://" + Configuration.elasticsearchUri)
val client = ElasticClient.remote(settings, uri)
I am trying to write it like:
def writeToElasticsearch(bulkList: List[EventMessage]) {
val ops = for (message <- bulkList) yield index into indexDcp ttl 7.days.toMillis doc StringDocumentSource(message.toJSon())
client.execute(bulk(ops: _*)).await
}
I am getting a compilation error in the bulk operation saying:
Multiple markers at this line
- type mismatch; found : List[com.sksamuel.elastic4s.IndexDefinition] required:
Seq[Int]
Can anyone tell me how I can convert the types to make this work? Thank you!
I'm not sure why you are getting errors, possibly something in the bits you've missed out of your code samples, but this version of your code compiles fine for me.
object Test extends App {
val client = ElasticClient.local
val indexDcp = "myindex/mytype"
import scala.concurrent.duration._
import ElasticDsl._
def writeToElasticsearch(bulkList: List[EventMessage]) {
val ops = for (message <- bulkList) yield { index into indexDcp ttl 7.days.toMillis doc StringDocumentSource(message.toJSon()) }
client.execute(bulk(ops: _*)).await
}
trait EventMessage {
def toJSon(): String
}
}

Get request with Rapture Http

I'm building an API with Rapture in Scala and having trouble resolving an issue with an implicit not being in scope. Here is the output from the error that I'm receiving.
[error] /Users/Petesta/Documents/scala-project/src/main/scala/scala-project/main.scala:35: an implicit TimeSystem is required; please import timeSystems.numeric or timeSystems.javaUtil
[error] Error occurred in an application involving default arguments.
[error] val response = h.get()
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 5 s, completed Oct 16, 2014 3:36:10 PM
Here is the code that it is failing on.
def getUser(userName: String) = {
val h = Http / "some_url" / "user" / userName /? Map('key -> "value")
val response = h.get()
}
I'm not sure what to do because I've tried importing both libraries separately and the error is still the same.
I've also added the -Xlog-implicits flag to see if something else is causing the error but no additional information is outputted.
Is there a good resource anywhere with using the rapture-net library for HTTP requests? I couldn't find one except for Jon Pretty's slides at Scala By The Bay. I couldn't figure out a way to pass in a url with query strings into rapture-uri since it expects function invocation to look like this uri"url_dot_domain_with_query_strings".slurp[Char].
Any ideas?
The compilation error is not entirely correct in this case. You need 1 of the 2 imports AND you need to specify a timeout value.
def getUser(userName: String) = {
import timeSystems.numeric
val h = Http / "some_url" / "user" / userName /? Map('key -> "value")
val response = h.get(timeout = 5000L)
}
I don't really know of a good resource on it, but your basic single code line is correct. The biggest problem with the library is really documentation about the imports required. But this is what I found works for me:
def getGoogle() = {
import rapture.codec._
import rapture.io._
import rapture.uri._
import rapture.net._
import encodings.`UTF-8`
uri"http://google.com".slurp[Char]
}