Skip to content

Commit

Permalink
Added track framework #99
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Jul 13, 2018
1 parent a8493cd commit 7ec074d
Show file tree
Hide file tree
Showing 21 changed files with 1,030 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bin/build_all
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ usage() {
echo ""
echo "Optional build targets:"
echo " -d tps,rest,admin"
echo " -p asset,unit, match,setting,rest,admin"
echo " -p asset,unit,match,setting,track,rest,admin"
echo ""
echo "Examples:"
echo " build_all "
Expand Down Expand Up @@ -76,6 +76,7 @@ PRD_CHOICES=$(echo "hashblock-asset-tp;
hashblock-unit-tp;
hashblock-match-tp;
hashblock-setting-tp;
hashblock-track-tp;
hashblock-rest;
hashblock-admin;"|tr -d '\n')
PRD_LOOKUP="asset;unit;match;setting;rest;admin"
Expand Down
4 changes: 4 additions & 0 deletions bin/protogen
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def main(args=None):
proto_dir,
"families/setting",
"hashblock_setting/protobuf")
protoc_python(
proto_dir,
"families/track",
"hashblock_track/protobuf")


def protoc_python(src_dir, base_dir, pkg):
Expand Down
29 changes: 29 additions & 0 deletions bin/track-tp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

# Copyright 2018 Frank V. Castellucci and Arthur Greef
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------

import os
import sys

sys.path.insert(0, os.path.join(
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
'families/track/hashblock_track'))


from processor.main import main

if __name__ == '__main__':
main()
19 changes: 19 additions & 0 deletions docker/compose/hashblock-distro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ services:
\""
stop_signal: SIGKILL

track-processor:
image: hashblock/hashblock-track-tp:latest
container_name: hashblock-track-tp-latest
restart: always
volumes:
- ../../../hbruntime:/project/private
environment:
- HASHBLOCK_KEYS=/project/private
- HASHBLOCK_CONFIG=/project/private
- PYTHONPATH=/project/hashblock-exchange
depends_on:
- asset-processor
command: "bash -c \"\
sleep 1 && \
track-tp -vv \
-C tcp://validator:4004 \
\""
stop_signal: SIGKILL

hashblock_rest:
image: hashblock/hashblock-rest:latest
container_name: hashblock-rest
Expand Down
18 changes: 18 additions & 0 deletions docker/compose/hashblock-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ services:
\""
stop_signal: SIGKILL

track-processor:
image: hashblock-dev-generic-tp
container_name: hashblock-dev-track-tp
volumes:
- ../..:/project/hashblock-exchange
environment:
- HASHBLOCK_KEYS=/project/hashblock-exchange/localkeys
- HASHBLOCK_CONFIG=/project/hashblock-exchange/localconfig
- PYTHONPATH=/project/hashblock-exchange
depends_on:
- validator
command: "bash -c \"\
sleep 1 &&
track-tp -vv \
-C tcp://validator:4004 \
\""
stop_signal: SIGKILL

settings-tp:
image: hyperledger/sawtooth-settings-tp:latest
container_name: sawtooth-settings-tp-local
Expand Down
19 changes: 19 additions & 0 deletions docker/compose/hashblock-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ services:
\""
stop_signal: SIGKILL

track-processor:
image: hashblock/hashblock-track-tp:latest
container_name: hashblock-track-tp-latest
restart: always
volumes:
- /sawtooth:/sawtooth
environment:
- HASHBLOCK_KEYS=/sawtooth/keys
- HASHBLOCK_CONFIG=/sawtooth/config
- PYTHONPATH=/project/hashblock-exchange
depends_on:
- asset-processor
command: "bash -c \"\
sleep 1 && \
track-tp -vv \
-C tcp://validator:4004 \
\""
stop_signal: SIGKILL

hashblock_rest:
image: hashblock/hashblock-rest:latest
container_name: hashblock-rest
Expand Down
94 changes: 94 additions & 0 deletions docker/hashblock-track-tp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

# ------------------------------------------------------------------------------
# Copyright 2018 Frank V. Castellucci and Arthur Greef
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------

# Description:
# Builds a deployable production image for our hashblock-track-tp
#
# base image:
# 1. Installs protobuf
# 2. Generates protobuf files
# final image:
# 1. Installs sawtooth-sdk and crypto
# 2. Copies relevant files from base
# Build:
# $ cd hashblock-exchange
# $ docker build . -f docker/hashblock-track-tp -t hashblock/hashblock-track-tp:latest
#

FROM ubuntu:xenial as base
LABEL maintainers="Frank V. Castellucci, Arthur Greef"

RUN apt-get update \
&& apt-get install -y -q \
apt-transport-https \
python3-dev \
python3-pip

RUN mkdir -p /builder && \
pip3 install \
grpcio-tools \
grpcio && \
rm -rf /var/lib/apt/lists/

WORKDIR /builder

COPY bin bin
COPY apps apps
COPY modules modules
COPY protos protos
COPY families families

RUN bin/protogen && \
pip3 uninstall -y grpcio grpcio-tools

# The final image

FROM ubuntu:xenial
LABEL maintainers="Frank V. Castellucci, Arthur Greef"

RUN apt-get update \
&& apt-get install -y -q \
apt-transport-https \
libssl-dev \
libffi-dev \
python3-dev \
python3-pip \
build-essential \
automake \
pkg-config \
libtool \
libffi-dev

RUN pip3 install eciespy cryptography && \
SECP_BUNDLED_EXPERIMENTAL=1 pip3 --no-cache-dir install --no-binary secp256k1 secp256k1 && \
pip3 install sawtooth-sdk --upgrade && \
rm -r /root/.cache && \
apt-get remove -y build-essential automake && apt-get autoremove -y

RUN mkdir -p /project/hashblock-exchange && \
mkdir -p /project/hashblock-exchange/bin && \
mkdir -p /project/hashblock-exchange/modules && \
mkdir -p /project/hashblock-exchange/families/track && \
mkdir -p /var/log/sawtooth

COPY --from=base /builder/bin/track-tp /project/hashblock-exchange/bin
COPY libs/hbzksnark /project/hashblock-exchange/bin
COPY --from=base /builder/modules /project/hashblock-exchange/modules
COPY --from=base /builder/families/track/hashblock_track /project/hashblock-exchange/families/track/hashblock_track

WORKDIR /project/hashblock-exchange
ENV PATH $PATH:/project/hashblock-exchange/bin
Empty file added families/track/__init__.py
Empty file.
Empty file.
14 changes: 14 additions & 0 deletions families/track/hashblock_track/processor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions families/track/hashblock_track/processor/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2017 Frank V. Castellucci
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
128 changes: 128 additions & 0 deletions families/track/hashblock_track/processor/config/track.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# ------------------------------------------------------------------------------
# Copyright 2018 Frank V. Castellucci and Arthur Greef
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------

import collections
import logging
import os

import toml

from sawtooth_sdk.processor.exceptions import LocalConfigurationError

LOGGER = logging.getLogger(__name__)


def load_default_track_config():
"""
Returns the default TrackConfig
"""
return TrackConfig(
connect='tcp://localhost:4004'
)


def load_toml_track_config(filename):
"""Returns a TrackConfig created by loading a TOML file from the
filesystem.
Args:
filename (string): The name of the file to load the config from
Returns:
config (TrackConfig): The TrackConfig created from the stored
toml file.
Raises:
LocalConfigurationError
"""
if not os.path.exists(filename):
LOGGER.info(
"Skipping transaction proccesor config loading from non-existent"
" config file: %s", filename)
return TrackConfig()

LOGGER.info("Loading transaction processor information from config: %s",
filename)

try:
with open(filename) as fd:
raw_config = fd.read()
except IOError as e:
raise LocalConfigurationError(
"Unable to load transaction processor configuration file:"
" {}".format(str(e)))

toml_config = toml.loads(raw_config)
invalid_keys = set(toml_config.keys()).difference(
['connect'])
if invalid_keys:
raise LocalConfigurationError(
"Invalid keys in transaction processor config: "
"{}".format(", ".join(sorted(list(invalid_keys)))))

config = TrackConfig(
connect=toml_config.get("connect", None)
)

return config


def merge_track_config(configs):
"""
Given a list of TrackConfig objects, merges them into a single
TrackConfig, giving priority in the order of the configs
(first has highest priority).
Args:
config (list of TrackConfigs): The list of units configs that
must be merged together
Returns:
config (TrackConfig): one TrackConfig that combines all of the
passed in configs.
"""
connect = None

for config in reversed(configs):
if config.connect is not None:
connect = config.connect

return TrackConfig(connect=connect)


class TrackConfig:
def __init__(self, connect=None):
self._connect = connect

@property
def connect(self):
return self._connect

def __repr__(self):
# not including password for opentsdb
return \
"{}(connect={})".format(
self.__class__.__name__,
repr(self._connect),
)

def to_dict(self):
return collections.OrderedDict([
('connect', self._connect),
])

def to_toml_string(self):
return str(toml.dumps(self.to_dict())).strip().split('\n')
Loading

0 comments on commit 7ec074d

Please sign in to comment.