Skip to content

Commit

Permalink
Merge pull request #2 from ZihengSun/main
Browse files Browse the repository at this point in the history
windows is not supported, add resetpassword, revise readme
  • Loading branch information
ZihengSun authored Apr 16, 2023
2 parents af18e56 + 76e1d14 commit df5aa8c
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 53 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,26 @@ geoweaver.stop()
3. To list the existing objects, please run:

```
geoweaver.list("host")
geoweaver.list("process")
geoweaver.list("workflow")
geoweaver.list_hosts()
geoweaver.list_processes()
geoweaver.list_workflows()
```

4. To run a workflow, please run:
```
geoweaver.run_workflow()
geoweaver.run_workflow("workflow_id", "host_id_list", "password_list", "environment_list")
```

or

```
geoweaver.run_workflow("workflow_zip_file_path", "host_id_list", "password_list", "environment_list")
```

or

```
geoweaver.run_workflow("workflow_local_folder_path", "host_id_list", "password_list", "environment_list")
```

5. To export a workflow:
Expand All @@ -47,42 +59,41 @@ geoweaver.export_workflow("workflow_id", "workflow_zip_save_path")
6. To import a workflow:

```
geoweaver.import_workflow("workflow_zip_file_path")
geoweaver.import_workflow("<workflow_zip_file_path>")
```

or

```
geoweaver.import_workflow("workflow_folder_path")
geoweaver.import_workflow("<workflow_folder_path>")
```

7. To get history of a workflow run:

```
geoweaver.history_workflow()
geoweaver.history("<workflow_history_id>")
```

8. To get history of a process run:

```
geoweaver.history_process()
geoweaver.history("<process_history_id>")
```

9. To check the source code of a process

```
geoweaver.detail_processs(process_id)
geoweaver.detail_processs("<process_id>")
```

10. To check the configuration of a workflow

```
geoweaver.detail_workflow(workflow_id)
geoweaver.detail_workflow("<workflow_id>")
```

11. To check the details of a host:

```
geoweaver.detail_host(host_id)
geoweaver.detail_host("<host_id>")
```

21 changes: 14 additions & 7 deletions pygeoweaver/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
The main function of pygeoweaver
To run in CLI mode.
"""
from pygeoweaver import detail_host, detail_process, detail_workflow
from pygeoweaver import export_workflow
from pygeoweaver import show_history
from pygeoweaver import import_workflow
from pygeoweaver import list_hosts, list_processes, list_workflows
from pygeoweaver import start, stop
from pygeoweaver import detail_host, detail_process, detail_workflow, export_workflow, \
show_history, import_workflow, list_hosts, list_processes, list_workflows, \
start, stop, reset_password, run_process, run_worklfow

def main():
# start geoweaver
Expand All @@ -29,7 +26,17 @@ def main():
#import_workflow("/Users/joe/Downloads/gr3ykr8dynu12vrwq11oy.zip")
# export workflow
# export_workflow("gr3ykr8dynu12vrwq11oy", "4", "/Users/joe/Downloads/test_pygeoweaver_export.zip")
# run workflow
# run process
# run_process(process_id="7zwnvx", host_id="100001", password="xxx", environment="",)
# run workflow by id
# run_worklfow(workflow_id="9sszomwhiiusakodb1ft", host_list="100001", password_list="xxx",
# environment_list="",)
# run workflow by zip path

# run workflow by folder path

# reset localhost password for Geoweaver
# reset_password()


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions pygeoweaver/sc_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
from pygeoweaver.sc_import import *
from pygeoweaver.sc_list import *
from pygeoweaver.sc_run import *
from pygeoweaver.server import *
from pygeoweaver.sc_resetpassword import *
13 changes: 13 additions & 0 deletions pygeoweaver/sc_resetpassword.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import subprocess
from pygeoweaver.utils import download_geoweaver_jar, get_geoweaver_jar_path, get_root_dir


def reset_password():
"""
Usage: <main class> resetpassword
Reset password for localhost
"""
download_geoweaver_jar()
subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "resetpassword",])

49 changes: 31 additions & 18 deletions pygeoweaver/sc_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,63 @@
from pygeoweaver.utils import download_geoweaver_jar, get_geoweaver_jar_path, get_root_dir


def run_process(*, process_id, host_id, password, environment):
if not host_id:
raise RuntimeError("Host id is missing")
def run_process(*, process_id: str, host_id: str, password: str, environment: str=None):
"""
Run a process
Args: process_id - required
host_id - required
password - required
environment - optional
"""
download_geoweaver_jar()
subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "process", f"--host={host_id}",
f"--password={password}", f"--environment={environment}", process_id],
cwd=f"{get_root_dir()}/")

def run_worklfow(*, workflow_id, workflow_folder_path, workflow_zip_file_path, environments, host, password):
def run_worklfow(*, workflow_id: str, workflow_folder_path: str=None, workflow_zip_file_path: str=None,
environment_list: str=None, host_list: str, password_list: str):
"""
Missing required parameter: '<workflowId>'
Usage: <main class> run workflow [-d=<workflowFolderPath>]
[-f=<workflowZipPath>] [-e=<envs>]...
[-h=<hostStrings>]... [-p=<passes>]...
<workflowId>
<workflowId> workflow id to run
-d, --workflow-folder-path=<workflowFolderPath>
geoweaver workflow folder path
-e, --environments=<envs> environments to run on
-e, --environments=<envs> environments to run on. List of environment ids with comma as separator
-f, --workflow-zip-file-path=<workflowZipPath>
workflow package or path to workflow zip to run
-h, --hosts=<hostStrings> hosts to run on
-p, --passwords=<passes> passwords to the target hosts
-h, --hosts=<hostStrings> hosts to run on. list of host ids with comma as separator.
-p, --passwords=<passes> passwords to the target hosts. list of passwords with comma as separator.
"""
download_geoweaver_jar()

if workflow_folder_path and workflow_zip_file_path:
raise RuntimeError("Please provide either Folder path or Zip path")
if not workflow_id and not workflow_folder_path and not workflow_zip_file_path:
raise RuntimeError("Please provide at least one of the three options: workflow id, " \
"folder path or zip path")

if workflow_id and not workflow_folder_path and not workflow_zip_file_path:
subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "workflow", workflow_id,
"-e", environment_list,
"-h", host_list,
"-p", password_list],
cwd=f"{get_root_dir()}/")

if workflow_folder_path and not workflow_zip_file_path:
# command to run workflow from folder
subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "workflow", workflow_id,
"-d", workflow_folder_path,
"-e", environments,
"-h", host,
"-p", password],
"-e", environment_list,
"-h", host_list,
"-p", password_list],
cwd=f"{get_root_dir()}/")

if not workflow_folder_path and workflow_zip_file_path:
subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "workflow", workflow_id,
"-e", environments,
"-e", environment_list,
"-f", workflow_zip_file_path,
"-h", host,
"-p", password],
"-h", host_list,
"-p", password_list],
cwd=f"{get_root_dir()}/")

raise RuntimeError("Please provide either zip path or directory path to run workflow.")

23 changes: 11 additions & 12 deletions pygeoweaver/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import subprocess
from pygeoweaver.utils import get_root_dir
from pygeoweaver.utils import checkOS, download_geoweaver_jar, get_root_dir

"""
This module provides function to start and stop Geoweaver server.
Expand All @@ -9,22 +9,21 @@
"""

def download_geoweaver():
"""
Download Geoweaver to user home directory
"""
pass


def start():
print("start Geoweaver instance..")
result = subprocess.run(['./start.sh'], cwd=f"{get_root_dir()}/")
def start(force=False):
download_geoweaver_jar(overwrite=force)
if checkOS() == 3:
raise RuntimeError("windows is not supported yet")
else:
result = subprocess.run(['./start.sh'], cwd=f"{get_root_dir()}/")



def stop():
print("stop Geoweaver instance..")
result = subprocess.run(['./stop.sh'], cwd=f"{get_root_dir()}/", shell=True)
if checkOS() == 3:
raise RuntimeError("Windows is not supported yet")
else:
result = subprocess.run(['./stop.sh'], cwd=f"{get_root_dir()}/", shell=True)



Expand Down
2 changes: 0 additions & 2 deletions pygeoweaver/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
echo "Stop running Geoweaver if any.."
pkill -f geoweaver



echo "Start Geoweaver.."
nohup java -jar ~/geoweaver.jar > ~/geoweaver.log &

Expand Down
11 changes: 10 additions & 1 deletion pygeoweaver/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import subprocess
import requests

import platform

def get_home_dir():
return os.path.expanduser('~')
Expand Down Expand Up @@ -39,3 +39,12 @@ def download_geoweaver_jar(overwrite=False):

else:
raise RuntimeError("Fail to download geoweaver.jar")


def checkOS():
if platform.system() == "Linux" or platform == "Linux2":
return 1
elif platform.system() == "Darwin":
return 2
elif platform == "Windows":
return 3
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pygeoweaver"
version = "0.6.2"
version = "0.6.4"
authors = [
{ name="Geoweaver team", email="[email protected]" },
]
Expand Down

0 comments on commit df5aa8c

Please sign in to comment.