Skip to content

Commit

Permalink
Merge pull request #1856 from singnet/development
Browse files Browse the repository at this point in the history
Requirements, Registry, Service Status and deployment updates
  • Loading branch information
sassless authored Dec 2, 2024
2 parents 4410757 + a97f8e5 commit c9a0b4c
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion common/ipfs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class IPFSUtil(object):

def __init__(self, ipfs_url, port):
self.ipfs_conn = ipfshttpclient.connect(f"/dns4/{ipfs_url}/tcp/{port}/http")
self.ipfs_conn = ipfshttpclient.connect(f"/dns/{ipfs_url}/tcp/{port}/http")

def read_bytesio_from_ipfs(self, ipfs_hash):
ipfs_data = self.ipfs_conn.cat(ipfs_hash)
Expand Down
3 changes: 2 additions & 1 deletion common/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ web3==5.10.0
requests==2.22.0
PyMySQL==0.10.1
boto3==1.15.9
ipfsapi==0.4.3
ipfsapi==0.4.4
ipfshttpclient==0.4.13.2
15 changes: 9 additions & 6 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,21 @@ def ipfsuri_to_bytesuri(uri):
return uri.encode("ascii").ljust(32 * (len(uri) // 32 + 1), b"\0")


def publish_file_in_ipfs(file_url, file_dir, ipfs_client, wrap_with_directory=True):
def publish_file_in_ipfs(file_url, file_dir, ipfs_client, wrap_with_directory=True, ignored_files=[]):
filename = download_file_from_url(file_url=file_url, file_dir=file_dir)
file_type = os.path.splitext(filename)[1]
logger.info(f" file type is = '{file_type.lower()}` ")
if file_type.lower() == ".zip":
return publish_zip_file_in_ipfs(filename, file_dir, ipfs_client)
return publish_zip_file_in_ipfs(filename, file_dir, ipfs_client, ignored_files=ignored_files)
#todo , you need to tar the folder and add that to the ipfs hash
logger.info(f"writing the file on ipfs {file_dir}/{filename} ")
ipfs_hash = ipfs_client.write_file_in_ipfs(f"{file_dir}/{filename}", wrap_with_directory)
return ipfs_hash


def publish_zip_file_in_ipfs(filename, file_dir, ipfs_client):
def publish_zip_file_in_ipfs(filename, file_dir, ipfs_client, ignored_files=[]):
logger.info(f"publish_zip_file_in_ipfs {file_dir}/{filename} ")
file_in_tar_bytes = convert_zip_file_to_tar_bytes(file_dir=file_dir, filename=filename)
file_in_tar_bytes = convert_zip_file_to_tar_bytes(file_dir=file_dir, filename=filename, ignored_files=ignored_files)
logger.info(f"file_in_tar_bytes {file_in_tar_bytes} ")
return ipfs_client.ipfs_conn.add_bytes(file_in_tar_bytes.getvalue())

Expand All @@ -262,13 +262,16 @@ def download_file_from_url(file_url, file_dir):
return filename


def convert_zip_file_to_tar_bytes(file_dir, filename):
def convert_zip_file_to_tar_bytes(file_dir, filename, ignored_files=[]):
with ZipFile(f"{file_dir}/{filename}", 'r') as zipObj:
listOfFileNames = zipObj.namelist()
zipObj.extractall(file_dir, listOfFileNames)
if not os.path.isdir(file_dir):
raise Exception("Directory %s doesn't exists" % file_dir)
files = glob.glob(os.path.join(file_dir, "*.proto"))
files = sorted(
f for f in glob.glob(os.path.join(file_dir, "*.proto"))
if os.path.basename(f) not in ignored_files
)
if len(files) == 0:
raise Exception("Cannot find any %s files" % (os.path.join(file_dir, "*.proto")))
files.sort()
Expand Down
3 changes: 2 additions & 1 deletion lambda_layers/common_python_libraries/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ sqlalchemy==1.3.5
aws-xray-sdk==2.4.2
botocore==1.19.55
boto3==1.16.1
ipfsapi==0.4.3
ipfsapi==0.4.4
ipfshttpclient==0.4.13.2
pymysql==0.9.2
setuptools==57.4.0
dxlmispservice==0.1.5
Expand Down
2 changes: 2 additions & 0 deletions lambda_layers/web3_and_grpc_libraries/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
rlp==1.2.0
protobuf==3.10.0
web3==5.10.0
ipfshttpclient==0.4.13.2
ipfsapi==0.4.4
grpcio==1.30.0
grpcio-health-checking==1.19.0
grpcio-tools==1.19.0
Expand Down
9 changes: 6 additions & 3 deletions registry/application/services/service_publisher_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,12 @@ def publish_service_data_to_ipfs(self):
filename = download_file_from_url(file_url=proto_url,
file_dir=f"{ASSET_DIR}/{service.org_uuid}/{service.uuid}")
logger.info(f"proto file Name Retrieved = '{filename}` ")
asset_ipfs_hash = publish_zip_file_in_ipfs(filename=filename,
file_dir=f"{ASSET_DIR}/{service.org_uuid}/{service.uuid}",
ipfs_client=IPFSUtil(IPFS_URL['url'], IPFS_URL['port']))
asset_ipfs_hash = publish_zip_file_in_ipfs(
filename=filename,
file_dir=f"{ASSET_DIR}/{service.org_uuid}/{service.uuid}",
ipfs_client=IPFSUtil(IPFS_URL['url'], IPFS_URL['port']),
ignored_files=["pricing.proto", "training.proto"]
)
service.proto = {
"model_ipfs_hash": asset_ipfs_hash,
"encoding": "proto",
Expand Down
2 changes: 1 addition & 1 deletion service_status/constant.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SRVC_STATUS_GRPC_TIMEOUT = 10
LIMIT = 5
LIMIT = 10
2 changes: 2 additions & 0 deletions service_status/service_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def update_service_status(self):
logger.info(f"error_details: {error_details}")
logger.info(f"debug_error_string: {debug_error_string}")
old_status = int.from_bytes(record["is_available"], "big")
logger.info(f"Service to check: row_id={record['row_id']}, status={status}, old_status={old_status}")
logger.info(f"Service endpoint: {record['endpoint']}")
failed_status_count = self._calculate_failed_status_count(
current_status=status, old_status=old_status,
old_failed_status_count=record["failed_status_count"])
Expand Down
2 changes: 2 additions & 0 deletions signer/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ package:
- License
- log_setup.py
- heath_check.sh
- node_modules/**
include:
- node_modules/singularitynet-platform-contracts/**
- resources/**


Expand Down
2 changes: 2 additions & 0 deletions wallets/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ package:
- License
- log_setup.py
- heath_check.sh
- node_modules/**
include:
- node_modules/singularitynet-platform-contracts/**
- resources/**


Expand Down

0 comments on commit c9a0b4c

Please sign in to comment.