Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptation for Gears/java #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 87 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,108 @@
version: 2.1

commands:
setup-executor:
steps:
- run:
name: Setup executor
command: |
apt-get -qq update
apt-get -q install -y git openssh-client curl ca-certificates make tar gzip
bash <(curl -fsSL https://raw.githubusercontent.com/docker/docker-install/master/install.sh)
- setup_remote_docker:
version: 20.10.7
docker_layer_caching: true

checkout-all:
steps:
- checkout
- run:
name: Checkout submodules
command: git submodule update --init --recursive

setup-automation:
steps:
- run:
name: Setup automation
command: |
git submodule update --init deps/readies
./deps/readies/bin/getpy3

install-prerequisites:
parameters:
redis_version:
type: string
default: "6"
getredis_params:
type: string
default: ""
steps:
- setup-automation
- run:
name: System setup
command: ./sbin/system-setup.py
- run:
name: Install Redis
shell: /bin/bash -l -eo pipefail
command: |
python3 ./deps/readies/bin/getredis -v '<<parameters.redis_version>>' --force <<parameters.getredis_params>>
redis-server --version

#----------------------------------------------------------------------------------------------------------------------------------

jobs:
test:
machine:
enabled: true
image: ubuntu-1604:201903-01
steps:
- checkout
- checkout-all
- setup-prerequisits
- run:
name: System Setup
command: |
sudo apt-get -qq update -y
sudo apt-get -q install -y curl ca-certificates wget make
(cd ..; git clone https://github.com/antirez/redis.git; cd redis; git checkout 5.0.8; make -j$(nproc); sudo make install)
sudo apt-get -q install -y make
SUDO=sudo make setup
- run:
name: Test
command: |
make test VERBOSE=1

test-rlec:
machine:
enabled: true
image: ubuntu-2004:202010-01
resource_class: large
working_directory: ~/AnimalRecognitionDemo
steps:
- checkout-all
- run:
name: Install prerequisites
command: |
./deps/readies/bin/getpy3
./sbin/system-setup.py
./deps/readies/bin/getredis
./deps/readies/bin/getdocker --just-enable-exp
docker version
python3 -m pip list
- run:
name: Install Arlecchino
command: |
cd
FORCE=1 ./AnimalRecognitionDemo/deps/readies/bin/getrlec
- run:
name: Start RLEC
shell: /bin/bash -l -eo pipefail
command: |
cd
mkdir -p rlec && chmod 777 rlec
./AnimalRecognitionDemo/deps/readies/bin/xtx -dMODULE=$(cd AnimalRecognitionDemo/bin/artifacts && ls *.zip) \
AnimalRecognitionDemo/tests/flow/rlec/redis-modules.yaml > rlec/redis-modules.yaml
rlec start --verbose --version 6.2.8 --build 53 --os bionic

#----------------------------------------------------------------------------------------------------------------------------------

workflows:
version: 2
build_and_package:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/readies"]
path = deps/readies
url = https://github.com/RedisLabsModules/readies.git
116 changes: 116 additions & 0 deletions app/gear.java

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions deps/readies
Submodule readies added at abb45e
26 changes: 26 additions & 0 deletions japp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# OSNICK=stretch|bionic|buster
ARG OSNICK=buster

#----------------------------------------------------------------------------------------------
FROM redisfab/redisedgevision-${OSNICK}:0.2.0

# This is due on the following error on ARMv8:
# /usr/lib/aarch64-linux-gnu/libgomp.so.1: cannot allocate memory in static TLS block
# Something is exausting TLS, causing libgomp to fail. Preloading it as a workaround helps.
# ENV LD_PRELOAD /usr/lib/aarch64-linux-gnu/libgomp.so.1

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get -qq update

RUN set -ex ;\
apt-get install -y wget python3-distutils ;\
wget -q https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py ;\
python3 /tmp/get-pip.py

WORKDIR /app
ADD . /app

RUN pip3 install -r requirements.txt

ENTRYPOINT [ "python3" ]
4 changes: 4 additions & 0 deletions japp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

all:
mvn compile
mvn package
42 changes: 42 additions & 0 deletions japp/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import argparse
import redis
from urllib.parse import urlparse

if __name__ == '__main__':
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--url', help='Redis URL', type=str, default='redis://127.0.0.1:6379')
args = parser.parse_args()

# Set up some vars
initialized_key = 'cats:initialized'

# Set up Redis connection
url = urlparse(args.url)
conn = redis.Redis(host=url.hostname, port=url.port)
if not conn.ping():
raise Exception('Redis unavailable')

# Check if this Redis instance had already been initialized
initialized = conn.exists(initialized_key)
if initialized:
print('Discovered evidence of a previous initialization - skipping.')
exit(0)

# # Load the RedisAI model
# print('Loading model - ', end='')
# with open('models/mobilenet_v2_1.4_224_frozen.pb', 'rb') as f:
# model = f.read()
# res = conn.execute_command('AI.MODELSET', 'mobilenet:model', 'TF', 'CPU', 'INPUTS', 'input', 'OUTPUTS', 'MobilenetV2/Predictions/Reshape_1', model)
# print(res)

# Load the gear
print('Loading gear - ', end='')
with open('gear.jar', 'rb') as f:
gear = f.read()
res = conn.execute_command('RG.JEXECUTE com.redis.AnimalRecognitionDemo.Server', gear)
print(res)

# Lastly, set a key that indicates initialization has been performed
print('Flag initialization as done - ', end='')
print(conn.set(initialized_key, 'miauw'))
30 changes: 30 additions & 0 deletions japp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.redis.animalrecognitiondemo</groupId>
<artifactId>animalrecognitiondemo-app</artifactId>
<version>1.0</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.redislabs</groupId>
<artifactId>gear_runtime</artifactId>
<version>0.0.3-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
116 changes: 116 additions & 0 deletions japp/src/main/java/com/redis/AnimalRecognitionDemo/App.java

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions sbin/system-setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import sys
import os
import argparse

ROOT = HERE = os.path.abspath(os.path.dirname(__file__))
READIES = os.path.join(ROOT, "deps/readies")
sys.path.insert(0, READIES)
import paella

#----------------------------------------------------------------------------------------------

class RedisTimeSeriesSetup(paella.Setup):
def __init__(self, nop=False):
paella.Setup.__init__(self, nop)

def common_first(self):
self.install("git jq curl unzip")
self.run("%s/bin/enable-utf8" % READIES, sudo=self.os != 'macos')
slef.install("java maven")

def debian_compat(self):
pass

def redhat_compat(self):
self.install("redhat-lsb-core")
self.run("%s/bin/getepel" % READIES, sudo=True)

def archlinux(self):
pass

def fedora(self):
pass

def macos(self):
self.install_gnu_utils()

def common_last(self):
self.run("{PYTHON} {READIES}/bin/getdocker --compose".format(PYTHON=self.python, READIES=READIES))
self.pip_install("-r {ROOT}/tests/flow/requirements.txt".format(ROOT=ROOT))
self.pip_install("gevent")

def linux_last(self):
pass

#----------------------------------------------------------------------------------------------

parser = argparse.ArgumentParser(description='Set up system for build.')
parser.add_argument('-n', '--nop', action="store_true", help='no operation')
args = parser.parse_args()

RedisTimeSeriesSetup(nop = args.nop).setup()