Skip to content

Commit

Permalink
Merge pull request #132 from AI-Planning/paas-fix
Browse files Browse the repository at this point in the history
Fixing some issues with the PaaS server.
  • Loading branch information
haz authored Sep 8, 2023
2 parents cc4bd5c + 5e9e264 commit a4728ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
19 changes: 19 additions & 0 deletions planutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def main():
parser_setup.add_argument('-f', '--force', help='force setting up again (will wipe all cached packages and settings)', action='store_true')
parser_upgrade = subparsers.add_parser('upgrade', help='upgrade all of the installed packages')

parser_configure = subparsers.add_parser('configure', help='configure planutils')
parser_configure.add_argument('-l', '--list', help='list the current configuration', action='store_true')
parser_configure.add_argument('-s', '--set', help='set a configuration option', nargs=2, metavar=('KEY', 'VALUE'))

parser_show = subparsers.add_parser('show', help='show details about a particular package')
parser_show.add_argument('package', help='package name', nargs='+')

Expand All @@ -115,6 +119,21 @@ def main():
else:
minimal_setup()

if 'configure' == args.command:
if args.list:
s = settings.load()
print("\nCurrent configuration:")
for k in s:
print(" %s: %s" % (k, s[k]))
print()
elif args.set:
s = settings.load()
s[args.set[0]] = args.set[1]
settings.save(s)
else:
parser_configure.print_help()
return

if 'check-installed' == args.command:
from planutils.package_installation import check_installed
exit({True:0, False:1}[check_installed(args.package)])
Expand Down
15 changes: 9 additions & 6 deletions planutils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def runPackage(package, service):

def package_remote_list():

package_url = settings.PAAS_SERVER + "/package"
package_url = settings.load()['PAAS_SERVER'] + "/package"
r = requests.get(package_url)
remote_packages = r.json()

Expand All @@ -119,8 +119,11 @@ def remote(target, options):

# 1. check if the target is deployed

package_url = settings.PAAS_SERVER + "/package"
r = requests.get(package_url)
package_url = settings.load()['PAAS_SERVER'] + "/package"
try:
r = requests.get(package_url)
except requests.exceptions.ConnectionError:
sys.exit(f"Could not connect to the server at {settings.load()['PAAS_SERVER']}")
remote_packages = r.json()

remote_package = None
Expand Down Expand Up @@ -165,16 +168,16 @@ def remote(target, options):

# 3. run the remote command

solve_url = '/'.join([settings.PAAS_SERVER, 'package', target, 'solve'])
solve_url = '/'.join([settings.load()['PAAS_SERVER'], 'package', target, 'solve'])
r = requests.post(solve_url, json=json_options)
if r.status_code != 200:
sys.exit(f"Error running remote call: {r.text}")

result_url = f"{settings.PAAS_SERVER}/{r.json()['result']}"
result_url = f"{settings.load()['PAAS_SERVER']}/{r.json()['result']}"

# call every 0.5s until the result is ready
result = None
for _ in range(settings.PAAS_SERVER_LIMIT):
for _ in range(settings.load()['PAAS_SERVER_LIMIT']):
r = requests.get(result_url)
if (r.status_code == 200) and ('status' in r.json()) and (r.json()['status'] == 'ok'):
result = r.json()['result']
Expand Down
8 changes: 6 additions & 2 deletions planutils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

SETTINGS_FILE = os.path.join(PLANUTILS_PREFIX, 'settings.json')

PAAS_SERVER = 'http://45.113.232.43:5001'
PAAS_SERVER_LIMIT = 100
DEFAULT_PAAS_SERVER = 'https://paas-uom.org:5001'
DEFAULT_PAAS_SERVER_LIMIT = 100

def load():
with open(SETTINGS_FILE, 'r') as f:
settings = json.loads(f.read())
return settings

def save(s):
if 'PAAS_SERVER' not in s:
s['PAAS_SERVER'] = DEFAULT_PAAS_SERVER
if 'PAAS_SERVER_LIMIT' not in s:
s['PAAS_SERVER_LIMIT'] = DEFAULT_PAAS_SERVER_LIMIT
with open(SETTINGS_FILE, 'w') as f:
f.write(json.dumps(s))
manifest_converter.generate_manifest()

0 comments on commit a4728ff

Please sign in to comment.