portkey

Portkey: from REPL to Serverless in one call
baptiste-from-paris 2017-10-02T07:46:37.000209Z

ok, thanks

baptiste-from-paris 2017-10-02T08:47:12.000005Z

for information, I have this error when trying a simple get call

baptiste-from-paris 2017-10-02T08:47:31.000120Z

Attempting to call unbound fn: #'clj-http.core/request: java.lang.IllegalStateException
java.lang.IllegalStateException: Attempting to call unbound fn: #'clj-http.core/request
at clojure.lang.Var$Unbound.throwArity(Var.java:45)
at clojure.lang.AFn.invoke(AFn.java:32)
at clojure.lang.Var.invoke(Var.java:381)
at clj_http.client$wrap_request_timing$fn__4812.invoke(client.clj:1046)
at clj_http.client$wrap_async_pooling$fn__4820.invoke(client.clj:1079)
at clj_http.headers$wrap_header_map$fn__2936.invoke(headers.clj:147)
at clj_http.client$wrap_query_params$fn__4700.invoke(client.clj:806)
at clj_http.client$wrap_basic_auth$fn__4706.invoke(client.clj:829)
at clj_http.client$wrap_oauth$fn__4711.invoke(client.clj:846)
at clj_http.client$wrap_user_info$fn__4720.invoke(client.clj:866)
at clj_http.client$wrap_url$fn__4794.invoke(client.clj:998)
at clj_http.client$wrap_decompression$fn__4471.invoke(client.clj:414)
at clj_http.client$wrap_input_coercion$fn__4624.invoke(client.clj:626)
at clj_http.client$wrap_additional_header_parsing$fn__4649.invoke(client.clj:681)
at clj_http.client$wrap_output_coercion$fn__4611.invoke(client.clj:570)
at clj_http.client$wrap_exceptions$fn__4418.invoke(client.clj:248)
at clj_http.client$wrap_accept$fn__4664.invoke(client.clj:724)
at clj_http.client$wrap_accept_encoding$fn__4671.invoke(client.clj:746)
at clj_http.client$wrap_content_type$fn__4658.invoke(client.clj:707)
at clj_http.client$wrap_form_params$fn__4767.invoke(client.clj:948)
at clj_http.client$wrap_nested_params$fn__4789.invoke(client.clj:983)
at clj_http.client$wrap_method$fn__4725.invoke(client.clj:882)
at clj_http.cookies$wrap_cookies$fn__1825.invoke(cookies.clj:131)
at clj_http.links$wrap_links$fn__3248.invoke(links.clj:63)
at clj_http.client$wrap_unknown_host$fn__4797.invoke(client.clj:1009)
at clj_http.client$request_STAR_.invokeStatic(client.clj:1181)
at clj_http.client$request_STAR_.invoke(client.clj:1174)
at clj_http.client$get.invokeStatic(client.clj:1187)
at clj_http.client$get.doInvoke(client.clj:1183)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at port.core$handler.invokeStatic(core.clj:61)
at port.core$handler.invoke(core.clj:56)
at portkey.core$mount_ring_BANG_$wrap__17167.invoke(core.clj:705)
at portkey.LambdaStub.handleRequest(LambdaStub.java:33

baptiste-from-paris 2017-10-02T08:48:01.000004Z

with this code

(defn handler
  [request]
  (response/response (client/get "<http://thecatapi.com/api/images/get?format=xml&amp;results_per_page=20>")))

viesti 2017-10-02T15:03:18.000533Z

hum, does it work with with older clojure, say 1.9.0-alpha19?

cgrand 2017-10-02T15:04:10.000484Z

I don’t know but I just reproduced @baptiste-from-paris error

viesti 2017-10-02T15:04:21.000336Z

neat

cgrand 2017-10-02T15:04:37.000491Z

and I checked clojure, no change around require handling

viesti 2017-10-02T15:05:18.000016Z

reproducible errors are warm and fuzzy

baptiste-from-paris 2017-10-02T15:10:50.000064Z

@viesti nope, same error

baptiste-from-paris 2017-10-02T15:15:21.000369Z

just to be sure, portkey only loads java class right ? For example, if you take the google-api-client, you have the key store which is store in a jks file and called like this =>

public static synchronized KeyStore getCertificateTrustStore()
      throws IOException, GeneralSecurityException {
    if (certTrustStore == null) {
      certTrustStore = SecurityUtils.getJavaKeyStore();
      InputStream keyStoreStream = GoogleUtils.class.getResourceAsStream("google.jks");
      SecurityUtils.loadKeyStore(certTrustStore, keyStoreStream, "notasecret");
    }
    return certTrustStore;
  }

baptiste-from-paris 2017-10-02T15:15:52.000525Z

it’s not found offcourse ^^, right ?

cgrand 2017-10-02T15:19:20.000304Z

It should be found

cgrand 2017-10-02T15:21:42.000728Z

We really need a verbose mode for packaging

baptiste-from-paris 2017-10-02T15:22:06.000069Z

ok, it’s not, at least keyStore is empty in lambda, working locally

baptiste-from-paris 2017-10-02T15:22:52.000655Z

by the way, you call keeps like that right ? => (pk/mount-ring! #'handler :keeps ["file1" "file2"])

viesti 2017-10-02T15:27:25.000259Z

yes, a set may be more descriptive, so #{"path/to/resource-on-classpath"}

viesti 2017-10-02T15:28:38.000217Z

for now, you can download the lambda zip to check that resource is there

viesti 2017-10-03T07:07:26.000183Z

no, being lazy 🙂 Maybe option for keeping the zip locally?

baptiste-from-paris 2017-10-02T15:28:55.000014Z

done that and it was not working

baptiste-from-paris 2017-10-02T15:29:05.000830Z

done some modifications

baptiste-from-paris 2017-10-02T15:31:19.000013Z

cause it seq’ like this (#{“path”}) so the (into {} (comp fn*) returns nil

baptiste-from-paris 2017-10-02T15:34:22.000114Z

I am not sure if I am right

baptiste-from-paris 2017-10-02T15:34:41.000603Z

but it’s working for me

baptiste-from-paris 2017-10-02T15:57:53.000081Z

no client/core

cgrand 2017-10-02T16:32:39.000394Z

You want us to step outside of the comfort or our repl? Never!

cgrand 2017-10-02T16:39:49.000021Z

(wrap-request #'core/request) a new trick to teach to the abstract interpreter

viesti 2017-10-02T17:32:27.000486Z

maybe this could even be behind a dynamic var, to look for new analysis at the repl: https://github.com/portkey-cloud/portkey/blob/master/src/main/clojure/portkey/analysis.clj#L112

baptiste-from-paris 2017-10-02T17:39:54.000201Z

analysis.clj is used for what ?

baptiste-from-paris 2017-10-02T17:55:24.000261Z

sorry again, but I got this new error that I never saw

Error loading class portkey.LambdaStub: java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
Caused by: com.esotericsoftware.kryo.KryoException: java.lang.IllegalStateException
Serialization trace:
provider (java.security.SecureRandom)
secureRandom (sun.security.ssl.SSLContextImpl$TLSContext)
contextSpi (javax.net.ssl.SSLContext)
sslContext (org.apache.http.nio.conn.ssl.SSLIOSessionStrategy)
map (org.apache.http.config.Registry)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:144)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:540)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:540)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:540)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:540)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:161)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:540)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813)
at carbonite.serializer$mk_collection_reader$fn__190.invoke(serializer.clj:57)
at clojure.lang.Var.invoke(Var.java:385)
at carbonite.ClojureVecSerializer.read(ClojureVecSerializer.java:17)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813)
at portkey.kryo$unfreeze.invokeStatic(kryo.clj:91)
at portkey.kryo$unfreeze.invoke(kryo.clj:87)
at portkey.core$bootstrap$fn__16755.invoke(core.clj:189)
at portkey.LambdaStub.&lt;clinit&gt;(LambdaStub.java:23)
... 2 more
Caused by: java.lang.IllegalStateException
at java.security.Provider.checkInitialized(Provider.java:650)
at java.security.Provider.check(Provider.java:655)
at java.security.Provider.put(Provider.java:317)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:162)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)

baptiste-from-paris 2017-10-02T17:55:50.000324Z

I am pretty sure it’s generated by this line => (ring.util.codec/form-decode body)

baptiste-from-paris 2017-10-02T17:56:42.000396Z

because it happened just after I added it

cgrand 2017-10-02T18:10:38.000412Z

@baptiste-from-paris thanks for trying it’s really really useful

cgrand 2017-10-02T18:12:09.000373Z

Analysis is about interpreting dynamic patterns used with mostly static arguments to get information on classes or Vars they may require

baptiste-from-paris 2017-10-02T18:33:04.000443Z

I think I can become addict to port key 😂! Would be awesome to connect a repl somehow

cgrand 2017-10-02T20:59:38.000349Z

My guess was wrong: our Kryo var serializer doesn’t kick in.