def terminate(uuid, new_time, limit, skip=False): """Remove all data associated with an environment.""" driver = GraphDatabase.driver(settings.NEO4J_URI, auth=(settings.NEO4J_USERNAME, settings.NEO4J_PASSWORD)) with driver.session() as session: # Attempt to locate environment by uuid env = find_environment(session, uuid) # If found, confirm termination msg = ('Confirming termination of environment with uuid \'{}\''.format( uuid)) confirmed = confirm_env_action(msg, skip=skip) if not confirmed: logger.info("Termination unconfirmed...cancelling.") exit(0) # Acquire lock and and terminate start = time.time() with lock_environment(driver, env): logger.debug("Acquired the lock.!!!") # Match relation ships with to property set to java end of time. # And bulk update until 0 matches. changed = set_to_until_zero(session, env, new_time, limit=limit) logger.info("Terminated {} relationships at {}.".format( changed, new_time)) logger.info("Completed termination in {:.3f}s".format(time.time() - start))
def sync_single(path, key=None): """Used to sync a single discrete set of run data. :param path: Path to run data :type path: str :param key: Encryption/Decryption base 64 encoded key :type key: str """ with DriverContext() as driver: run = runs.Run(path, key=key) env = EnvironmentEntity(uuid=run.environment_uuid, name=run.environment_name, account_number=run.environment_account_number) with lock_environment(driver, env): sync_run(driver, run)
def sync_paths(paths): """Sync all runs indicated by paths. :param paths: list of paths indicating runs. :type paths: list """ # Start a neo4j driver context. with DriverContext() as driver: for path in paths: run = runs.Run(path) # Try to acquire environment lock. # @TODO - Implement wait until timeout loop. try: with lock_environment(driver, run): sync_run(driver, run) except EnvironmentLockedError as e: logger.error(e)
def sync(paths): with DriverContext() as driver: for path in paths: run = runs.Run(path) with lock_environment(driver, run): try: check_run_time(driver, run) run.start() logger.info("Starting collection on {}".format(run.path)) consume(driver, run) logger.info("Run completion time: {}".format( utils.milliseconds(run.completed))) run.finish() except RunAlreadySyncedError as e: logger.info(e) except RunInvalidStatusError as e: logger.info(e) except RunContainsOldDataError as e: logger.info(e) except Exception: logger.exception('Unable to complete run.') run.error()
def remove(uuid, skip=False): """Remove all data associated with an environment.""" driver = GraphDatabase.driver(settings.NEO4J_URI, auth=(settings.NEO4J_USERNAME, settings.NEO4J_PASSWORD)) with driver.session() as session: # Attempt to locate environment by account number and name env = find_environment(session, uuid) # If found, confirm deletion msg = 'Confirm deleting of environment with uuid \'{}\''.format(uuid) confirmed = confirm_env_action(msg, skip=skip) if not confirmed: logger.info("Removal unconfirmed...cancelling.") exit(0) # Acquire lock and delete with lock_environment(driver, env): logger.debug("Acquired the lock.!!!") # get all paths paths = [] for label, model in registry.models.items(): path = [l for l, r in registry.path(label)] path.append(label) paths.append(path) paths.sort(key=lambda x: len(x)) logger.debug(pprint.pformat(paths)) stats = {} for path in reversed(paths): prune(session, env, path, stats) logger.info("Deleted node counts by type:\n{}".format( pprint.pformat(stats)))