Skip to content

Commit

Permalink
Adjust files to the running version on the server. Some parts of the …
Browse files Browse the repository at this point in the history
…code should be tested again and removed or corrected
  • Loading branch information
MarcusStrobl committed Apr 25, 2024
1 parent ea8080b commit b305f70
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
46 changes: 24 additions & 22 deletions processes/podman_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,37 @@ def connect(uri='unix:///run/podman/podman.sock'):
else:
print("Podman service is running")
logging.info("Podman service is running")
version = client.version()
print("Release: ", version["Version"])
logging.info("Release: ", version["Version"])
print("Compatible API: ", version["ApiVersion"])
logging.info("Compatible API: ", version["ApiVersion"])
print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n")
logging.info("Podman API: ", version["Components"][0]["Details"]["APIVersion"])
# TODO: There is a bug in the following code. Fix it
# version = client.version()
# print("Release: ", version["Version"])
# logging.info("Release: ", version["Version"])
# print("Compatible API: ", version["ApiVersion"])
# logging.info("Compatible API: ", version["ApiVersion"])
# print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n")
# logging.info("Podman API: ", version["Components"][0]["Details"]["APIVersion"])

return client

def pull_run_image(client, image_name, container_name, environment=None, mounts=None, network_mode=None,
volumes=None, command=None):
secrets = PodmanProcessor.get_secrets()
# Log available Docker image
logging.info("The following images are available: ")
for i in client.images.list():
logging.info(f"Image ID: {i.id}, image name: {i.name}")
logging.info(f"client.images.list() {client.images.list()}")
# logging.info("The following images are available: ")
# for i in client.images.list():
# logging.info(f"Image ID: {i.id}, image name: {i.name}")

# Pull the Docker image
print("image: ", client.images.list(filters={"reference": image_name}))
logging.info("image: ", client.images.list(filters={"reference": image_name}))
if not client.images.list(filters={"reference": image_name}):
print(f"Pulling Podman image: {image_name}")
logging.info(f"Pulling Podman image: {image_name}")
client.images.pull(image_name)
# print("image: ", client.images.list(filters={"reference": image_name}))
# logging.info("image: ", client.images.list(filters={"reference": image_name}))
# if not client.images.list(filters={"reference": image_name}):
# print(f"Pulling Podman image: {image_name}")
# logging.info(f"Pulling Podman image: {image_name}")
# client.images.pull(image_name)

existing_container = client.containers.list(filters={"name": container_name})
if existing_container:
print(f"Container '{container_name}' already exists. Removing...")
# print(f"Container '{container_name}' already exists. Removing...")
logging.info(f"Container '{container_name}' already exists. Removing...")
existing_container[0].stop()
existing_container[0].remove(force=True)
Expand Down Expand Up @@ -71,20 +73,20 @@ def pull_run_image(client, image_name, container_name, environment=None, mounts=
# status of the container after starting
container.reload()
logging.info("Container reloaded")
print("container starting status :", container.status)
# print("container starting status :", container.status)
logging.info("container starting status :", container.status)

# Print container logs
print(f"Container '{container.name}' logs:")
# print(f"Container '{container.name}' logs:")
logging.info(f" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Container '{container.name}' logs: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ")
for line in container.logs(stream=True):
print(line.strip().decode('utf-8'))
# print(line.strip().decode('utf-8'))
logging.info(f" - - {line.decode('utf-8')} - - ")
logging.info(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ fnished logs _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ")
logging.info(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ finished logs _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ")

# exit status code
exit_status = container.wait()
print("exit_status :", exit_status)
# print("exit_status :", exit_status)
logging.info("exit_status :", exit_status)

# status of the container
Expand Down
19 changes: 18 additions & 1 deletion processes/tool_vforwater_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@
'minOccurs': 1, # expect the data is required
'maxOccurs': 1,
},
# 'integration': {
# 'title': 'Define how result is handled on server.',
# 'description': 'Set if the results should be written to disk. All = can improve processing, '
# 'none = slower but with result, XXX = faster but only for workflows'
# 'BE AWARE, setting this parameter to XXX might result in no result at all.',
# 'schema': {
# 'type': 'string',
# 'enum': ['none', 'all', 'XXX'],
# 'default': 'none',
# 'required': 'true'
# },
# },
},
'outputs': {
'res': {
Expand Down Expand Up @@ -187,6 +199,9 @@ def execute(self, data):
start_date = data.get('start_date', '') # path/name to numpy.ndarray
end_date = data.get('end_date', '') # integer
reference_area = data.get('reference_area', {})
# TODO: integration becomes important in future versions, when we have workflows. For now this should be always
# none, so the parameter is not available for the user. Uncomment it when needed
integration = data.get('integration', 'none')

user = data.get('User-Info', "NO_USER")

Expand Down Expand Up @@ -219,6 +234,7 @@ def execute(self, data):
input_dict = {
"vforwater_loader": {
"parameters": {
"integration": integration,
"dataset_ids": dataset_ids,
"start_date": start_date,
"end_date": end_date,
Expand Down Expand Up @@ -256,7 +272,8 @@ def execute(self, data):
# ________________ prepare data to run container _________________________
logging.info('Prepare container data')
# image_name = 'vfwregistry:5000/demo/tool_vforwater_loader:0.1'
image_name = 'tool_vforwater_loader:0.1'
# image_name = 'tool_vforwater_loader:0.2' # TODO: used for test; still valid?
image_name = 'tool_vforwater_loader:latest'
# image_name = 'ghcr.io/vforwater/tbr_vforwater_loader:latest'
container_name = f'tool_vforwater_loader_{os.urandom(5).hex()}'

Expand Down

0 comments on commit b305f70

Please sign in to comment.