Skip to content

Commit

Permalink
updates to start pinging spackmon for build statuses
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Feb 17, 2021
1 parent 9aa823b commit 64c4eb0
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 58 deletions.
15 changes: 10 additions & 5 deletions lib/spack/spack/cmd/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def setup_parser(subparser):
'--monitor', action='store_true', dest='use_monitor', default=False,
help="interact with a montor server during builds.")
monitor_group.add_argument(
'--monitor-no-auth', action='store_true', dest='monitor_disable_auth',
'--monitor-no-auth', action='store_true', dest='monitor_disable_auth',
default=False, help="the monitoring server does not require auth.")
monitor_group.add_argument(
'--monitor-keep-going', action='store_true', dest='monitor_keep_going',
'--monitor-keep-going', action='store_true', dest='monitor_keep_going',
default=False, help="continue the build if a request to monitor fails.")
monitor_group.add_argument(
'--monitor-host', dest='monitor_host', default="http://127.0.0.1",
Expand Down Expand Up @@ -229,6 +229,7 @@ def install_specs(cli_args, kwargs, specs):
else:
installs = [(concrete.package, kwargs) for _, concrete in specs]
builder = PackageInstaller(installs)
builder.add_monitor_client(cli_args)
builder.install()
except spack.build_environment.InstallError as e:
if cli_args.show_log_on_error:
Expand Down Expand Up @@ -257,12 +258,12 @@ def install(parser, args, **kwargs):

# The user wants to monitor builds using github.com/spack/spack-monitor
if args.use_monitor:
spack.monitor.get_client(
monitor = spack.monitor.get_client(
host=args.monitor_host,
prefix=args.monitor_prefix,
disable_auth=args.monitor_disable_auth
);
)

reporter = spack.report.collect_info(
spack.package.PackageInstaller, '_install_task', args.log_format, args)
if args.log_file:
Expand Down Expand Up @@ -398,4 +399,8 @@ def install(parser, args, **kwargs):
# overwrite all concrete explicit specs from this build
kwargs['overwrite'] = [spec.dag_hash() for spec in specs]

# If we are using the monitor, we send original configs.
# The full_hash is the main package id, the build_hash for others
if args.use_monitor:
monitor.new_configuration(specs)
install_specs(args, kwargs, zip(abstract_specs, specs))
11 changes: 9 additions & 2 deletions lib/spack/spack/cmd/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def setup_parser(subparser):
subparser.add_argument(
'-N', '--namespaces', action='store_true', default=False,
help='show fully qualified package names')
subparser.add_argument(
'--hash-type', default="build_hash",
choices=['build_hash', 'full_hash', 'dag_hash'],
help='generate spec with a particular hash type.')
subparser.add_argument(
'-t', '--types', action='store_true', default=False,
help='show dependency types')
Expand Down Expand Up @@ -83,11 +87,14 @@ def spec(parser, args):
if spec.name in spack.repo.path or spec.virtual:
spec.concretize()

# The user can specify the hash type to use
hash_type = getattr(ht, args.hash_type)

if args.format == 'yaml':
# use write because to_yaml already has a newline.
sys.stdout.write(spec.to_yaml(hash=ht.build_hash))
sys.stdout.write(spec.to_yaml(hash=hash_type))
else:
print(spec.to_json(hash=ht.build_hash))
print(spec.to_json(hash=hash_type))
continue

with tree_context():
Expand Down
5 changes: 5 additions & 0 deletions lib/spack/spack/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,11 @@ def install_all(self, args=None, **install_args):

try:
builder = PackageInstaller(installs)

# If the user has requested a monitor client, attach to builder
if install_args.get('use_monitor', False):
builder.init_monitor_client(install_args)

builder.install()
finally:
# Ensure links are set appropriately
Expand Down
38 changes: 31 additions & 7 deletions lib/spack/spack/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import spack.compilers
import spack.error
import spack.hooks
import spack.monitor
import spack.package
import spack.package_prefs as prefs
import spack.repo
Expand Down Expand Up @@ -641,6 +642,9 @@ def __init__(self, installs=[]):
# fast then that option applies to all build requests.
self.fail_fast = False

# A Monitor client will interact with a monitor server at each step
self.monitor = None

def __repr__(self):
"""Returns a formal representation of the package installer."""
rep = '{0}('.format(self.__class__.__name__)
Expand All @@ -658,6 +662,16 @@ def __str__(self):
return '{0}: {1}; {2}; {3}; {4}'.format(
self.pid, requests, tasks, installed, failed)

def add_monitor_client(self, args):
"""Given that the args.use_monitor is true, instantiate a client
"""
if args.use_monitor:
self.monitor = spack.monitor.get_client(
host=args.monitor_host,
prefix=args.monitor_prefix,
disable_auth=args.monitor_disable_auth
)

def _add_bootstrap_compilers(
self, compiler, architecture, pkgs, request, all_deps):
"""
Expand Down Expand Up @@ -1390,16 +1404,10 @@ def install(self):
Args:
pkg (Package): the package to be built and installed"""

print("IN INSTALLER")
import IPython
IPython.embed()
sys.exit(0)

# STOPPED HERE - need to trace this and add appropriate endpoints
spack.monitor.get_client(
host=args.monitor_host,
prefix=args.monitor_prefix,
disable_auth=args.monitor_disable_auth
);

self._init_queue()

Expand All @@ -1426,6 +1434,7 @@ def install(self):
# dependencies handling). So terminate under the assumption that
# all subsequent tasks will have non-zero priorities or may be
# dependencies of this task.

if task.priority != 0:
tty.error('Detected uninstalled dependencies for {0}: {1}'
.format(pkg_id, task.uninstalled_deps))
Expand All @@ -1435,6 +1444,15 @@ def install(self):
tty.warn('{0} does NOT actually have any uninstalled deps'
' left'.format(pkg_id))
dep_str = 'dependencies' if task.priority > 1 else 'dependency'

# Update the endpoint to indicate the failure (cancel)
# Here we do not consider fail fast, as an error is raised.
# TODO: this currently marks the main task as failed -
# in the future we want the main task to be cancelled,
# and the task that failed marked as failed.
if self.monitor:
self.monitor.fail_task(task.request.pkg)

raise InstallError(
'Cannot proceed with {0}: {1} uninstalled {2}: {3}'
.format(pkg_id, task.priority, dep_str,
Expand All @@ -1454,6 +1472,12 @@ def install(self):
tty.warn('{0} failed to install'.format(pkg_id))
self._update_failed(task)

# Mark that the package failed
# TODO: this should also be for the task.pkg, but we don't
# model transitive yet.
if self.monitor:
self.monitor.fail_task(task.request.pkg)

if self.fail_fast:
raise InstallError(fail_fast_err)

Expand Down

0 comments on commit 64c4eb0

Please sign in to comment.