def execute(self): """Execute command.""" LOG.debug(f'{self.msg_src}: Execute: Target:' f' {self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET)}') cmd_target = self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET) if cmd_target == CLI_CMDTARGET.STORAGE: # (Re)build/repair the installation storage structure. self.config.inst_storage.construct( clean=self.cmd_opts.get(CLI_CMDOPT.INST_CLEAN)) elif cmd_target == CLI_CMDTARGET.PKGALL: # If there is a state file, then install/update failed previously. # If there is a Mesos exe, then there is an existing installation. # In either case, we fail setup. state = self.state.get_state() if state is not None: raise cm_exc.InstallationError( f'Cannot install DC/OS: detected state {state}') test_file = self.config.inst_storage.root_dpath / 'bin' / 'mesos-agent.exe' if test_file.exists(): raise cm_exc.InstallationError( f'Cannot install DC/OS: detected existing cluster {test_file}' ) self.state.set_state(STATE_INSTALLING) self._handle_cmdtarget_pkgall() self.state.set_state(STATE_NEEDS_START) else: raise NotImplementedError() LOG.info(f'{self.msg_src}: Install: OK')
def execute(self): """Execute command.""" LOG.debug(f'{self.msg_src}: Execute ...') state = self.state.get_state() if state is not None: raise cm_exc.InstallationError( f'Cannot upgrade DC/OS: detected state {state}') test_file = self.config.inst_storage.root_dpath / 'bin' / 'mesos-agent.exe' if not test_file.exists(): raise cm_exc.InstallationError( f'Cannot upgrade DC/OS: no file at {test_file}') self.state.set_state(STATE_UPGRADING) self._handle_upgrade() self.state.set_state(STATE_NEEDS_START)
def execute(self): """Execute command.""" state = self.state.get_state() if state is not None and state != STATE_NEEDS_START: raise cm_exc.InstallationError( f'Cannot start DC/OS: detected state {state}' ) test_file = self.config.inst_storage.root_dpath / 'bin' / 'mesos-agent.exe' if not test_file.exists(): raise cm_exc.InstallationError( f'Cannot start DC/OS: no file at {test_file}' ) pkg_manifests = ( self.config.inst_storage.get_pkgactive(PackageManifest.load) ) packages_bulk = { m.pkg_id.pkg_name: Package(manifest=m) for m in pkg_manifests } for package in cr_utl.pkg_sort_by_deps(packages_bulk): pkg_id = package.manifest.pkg_id mheading = f'{self.msg_src}: Execute: {pkg_id.pkg_name}' # TODO: This part should be replaced with # Package.handle_svc_start() method if package.svc_manager: svc_name = package.svc_manager.svc_name LOG.debug(f'{mheading}: Start service: {svc_name}: ...') try: self.service_start(package.svc_manager) except (svcm_exc.ServiceError, svcm_exc.ServiceManagerError) as e: LOG.error(f'{mheading}: Start service:' f' {type(e).__name__}: {e}') else: LOG.debug(f'{mheading}: Start service: {svc_name}: OK') else: LOG.debug(f'{mheading}: Start service: NOP') self.state.unset_state()
def pkg_sort_by_deps(packages): """Get a list of package manager objects sorted by mutual dependencies of their associated DC/OS packages. Ref: [1] Topological sorting. https://en.wikipedia.org/wiki/Topological_sorting :param packages: dict(<pkg_name>: Package), set of DC/OS package manager objects :return: list(Package), ordered sequence of DC/OS package manager objects """ msg_src = 'pkg_sort_by_deps()' pkg_names_order_base = ['vcredist', 'nssm', 'bootstrap'] LOG.debug(f'{msg_src}: pkg_names_order_base: {pkg_names_order_base}') pkg_names_provided = set(packages) LOG.debug(f'{msg_src}: pkg_names_provided: {pkg_names_provided}') pkg_names_required = set(pkg_names_order_base) LOG.debug(f'{msg_src}: pkg_names_required: {pkg_names_required}') pkg_names_other = set(pkg_names_provided) pkg_names_other.difference_update(pkg_names_required) LOG.debug(f'{msg_src}: pkg_names_other: {pkg_names_other}') pkg_names_missed = pkg_names_required.difference(pkg_names_provided) LOG.debug(f'{msg_src}: pkg_names_missed: {pkg_names_missed}') if pkg_names_missed: raise cm_exc.InstallationError( f'Resolve DC/OS packages mutual dependencies: Required packages' f' not found within DC/OS installation local package repository:' f' {pkg_names_missed}' ) packages_sorted = [ packages[pkg_name] for pkg_name in pkg_names_order_base ] packages_sorted[len(packages_sorted):] = [ packages[pkg_name] for pkg_name in sorted(pkg_names_other) ] # TODO: Implement topological sorting algorithm using package mutual # dependencies information from the 'requires' element of the # pkginfo.json file provided with a package instead of the # placeholder implementation above. return packages_sorted