Starcraft Bladder problems: Of things that are not supported

I very wisely foresaw that the Bot Ladder (terribly nicknamed BLADDER, if you suggest a better name, I 100% seriously buy you a pizza) will have some huge clusterfucks minor technical annoyances along the way, just maybe enough for a second article.

Previously, I managed to launch Starcraft, and inject stuff into it. (This is a sentence when overheard by old people in the bus, will result in tabloid article). Then the UI design part then commenced. Of course it looks like an expensive, yet utterly useless internal business app at this stage, but hey, humble starts.

Nem érhető el leírás a fényképhez.
UX design awards 2019

The Play button even works! The others you can push without repercussions, and that’s the extent of their functionality. The Making of Placeholders has begun. I really can’t say anything really bad about JavaFX, I found it quite usable. I’d like to mention this tutorial, as it is light-hearted, but still explains the basics quite well. It has it’s quirks of course, and sometimes it’s not that intuitive, but in the grand scheme of things – and compared to some Java frameworks – it was a delight to work with.

Unlike other parts.

I started to work on the coordinator server for the bot ladder. I thought, in my infinite naivete, that a simple REST service is all I need. So I planned to use JAX-RS, which might be not the latest functional microservice-based bleeding edge solution, but in general, it does the job. Also, not supported – I found that out by finding a removed page on the google cloud tutorials, and of course, frustrated Stack Overflow posts. I built the Spring Boot application from the tutorials, that worked somewhat, but only got working it with servlets. Which is really cutting-edge – for about 2003, that is – but meh, it works. (Fun activity: Search for “how relevant/modern are servlets”) Okay, as long as it works, I can go with this. Configuring them isn’t trivial, but can be done with a reasonable amount of figuring outing.

Then the descent into madness started. We are using Google App Engine. It is all and well, and you have a lot of tutorials. The main problem with those is, well, they don’t fucking work. The other problem is, if you google anything remotely related to them, the first search result will be one of these tutorials. Which I completely get – Google pushing it’s own agenda, I’m not even mad about that, but I usually can’t find anything on Stack Overflow, or related. I’m pretty sure this is intentional, but my suspicions will never be confirmed.

First, I decided to go with PostgreSQL DB. Don’t ask me why, I was young and needed the money. The tutorial lets you set up the DB, that went without any serious issue, but then there is the issue of well, connecting to it, which is rather paramount to the application. I’m supposed to use this command:

gcloud sql connect myinstance --user=postgres

Which has a small problem of not working. Upon searching and searching, in some back corner of the internet I got the answer that this is a beta feature for some reason.

gcloud sql beta connect myinstance --user=postgres

This worked. Mind you, the error message (“HTTPError 400: The incoming request contained invalid data.”) is less than helpful in this regard. Might as well just go with “BadThingsHappenedException: Shit went wrong, yo”. Every time I describe something like this, imagine googling stuff for an hour.

Okay, I can log in via the psql console. Not any GUI tool, mind you – still haven’t figured that one out -. Clunky, but works.

Okay, now do that from an app engine application. Contrary to the info here, which is the first thing if you google “connect to google cloud postgresql from app engine”. I tried every way possible, manually edited, and built the connection string to no avail. No wonder, what I actually needed was this tutorial, which is absolutely indistinguishable at a glance, describes a whole different process, and surprise, surprise, does not work.

I added some basic tables, and servlets to experiment. If you use the connection string example provided, you just get an error.

The SocketFactory class provided com.google.cloud.sql.postgres.SocketFactory could not be instantiated.  

There is a GitHub issue, of course without an actual solution for the problem, which is to change the argument to “cloudsqlinstance”, described here. Needless to say, this required some googling, and trying out.

Also, during this process , I found out that my socket library, and postgresql maven dependency was not necessarily the proper version. I mean, you would think if they provide a version in the example, that supports it. Another pro tip is to not waste a considerable amount of time using the mysql socketfactory, when you have a postgresql db. No matter how many times you deploy, it won’t work.

From the code examples, there is an important, and useful part.

  @Override
    public void init() throws ServletException {
        String url;

        Properties properties = new Properties();
        try {
            properties.load(
                    getServletContext().getResourceAsStream("/WEB-INF/classes/config.properties"));
            url = properties.getProperty("sqlUrl");
        } catch (IOException e) {
            log("no property", e);  // Servlet Init should never fail.
            return;
        }

        log("connecting to: " + url);
        try {
            Class.forName("org.postgresql.Driver");
            conn = DriverManager.getConnection(url);
        } catch (ClassNotFoundException e) {
            throw new ServletException("Error loading JDBC Driver", e);
        } catch (SQLException e) {
            throw new ServletException("Unable to connect to PostGre", e);
        } finally {
            // Nothing really to do here.
        }
    }

It does things.

So few words can’t really convey how exhausting it was to reach this point, but it works now. I have to clean up the code now, as I have remnants of about 10 broken dreams failed approaches, but the actual development can now begin. Maybe the emotional healing as well.

TL;DR: am now google cloud expert, hire me for 150 $ / hour.

Leave a Reply