Ejemplo n.º 1
0
    def _snitch(self, session):
        """Orchestrates the creation of the environment.

        :param session: neo4j driver session
        :type session: neo4j.v1.session.BoltSession
        """
        # Load saved git data
        try:
            filename = os.path.join(self._basedir(), 'gitrepos.json')
            with open(filename, 'r') as f:
                gitdata = json.loads(f.read())
        except IOError:
            logger.info('No data for git could be found.')
            return

        # Let model compute environment identity
        env = EnvironmentEntity(
            account_number=gitdata['environment']['account_number'],
            name=gitdata['environment']['name'])
        identity = env.identity

        # Try to locate environment by identity
        env = EnvironmentEntity.find(session, identity)
        if env is None:
            logger.warning('Unable to locate environment {}.'.format(identity))
            return

        # Iterate over each git repo
        gitrepos = []
        for gitdict in gitdata.get('data', []):
            gitrepo = self._update_gitrepo(session, env, gitdict)
            gitrepos.append(gitrepo)

        # Update edges
        env.gitrepos.update(session, gitrepos, self.time_in_ms)
Ejemplo n.º 2
0
    def _snitch(self, session):
        """Orchestrates the creation of the environment.

        :param session: neo4j driver session
        :type session: neo4j.v1.session.BoltSession
        """
        # Load saved git data
        try:
            gitdata = self.run.get_object('gitrepos.json')
        except IOError:
            logger.info('No data for git could be found.')
            return

        # Try to locate environment by identity
        uuid = self.run.environment_uuid
        env = EnvironmentEntity.find(session, uuid)
        if env is None:
            logger.warning('Unable to locate environment {}.'.format(uuid))
            return

        # Iterate over each git repo
        gitrepos = []
        for gitdict in gitdata.get('data', []):
            gitrepo = self._update_gitrepo(session, env, gitdict)
            gitrepos.append(gitrepo)

        # Update edges
        env.gitrepos.update(session, gitrepos, self.time_in_ms)
Ejemplo n.º 3
0
def find_environment(session, uuid):
    """Find an environment by uuid.

    :param session: neo4j driver session
    :type session: neo4j.v1.session.BoltSession
    :param uuid: UUID of the environment
    :type uuid: str
    :returns: Environment entity
    :rtype: EnvironmentEntity
    """
    env = EnvironmentEntity.find(session, uuid)
    if env is None:
        raise EnvironmentNotFoundError(uuid)
    return env
Ejemplo n.º 4
0
def check_run_time(driver, run):
    """Prevent a run from updating an environment.

    Protects an environment with newer data from a run with older data.

    :param driver: Neo4J database driver instance
    :type driver: neo4j.v1.GraphDatabase.driver
    :param run: Date run instance
    :type run: cloud_snitch.runs.Run
    """
    # Check to see if run data is new
    with driver.session() as session:
        e = EnvironmentEntity.find(session, run.environment_uuid)

        # If the environment exists, check its last update
        if e is not None:
            last_update = utils.utcdatetime(e.last_update(session) or 0)
            logger.debug("Comparing {} to {}".format(run.completed,
                                                     last_update))
            if run.completed <= last_update:
                raise RunContainsOldDataError(run, last_update)
Ejemplo n.º 5
0
    def _snitch(self, session):
        """Orchestrates the creation of the environment.

        :param session: neo4j driver session
        :type session: neo4j.v1.session.BoltSession
        """
        # Load saved git data
        try:
            uservars_dict = self.run.get_object('uservars.json')
        except IOError:
            logger.info('No data for uservars could be found.')
            return

        # Try to find the parent environment.
        env = EnvironmentEntity(uuid=self.run.environment_uuid)
        identity = env.identity
        env = EnvironmentEntity.find(session, identity)
        if env is None:
            logger.warning(
                'Unable to locate environment {}.'.format(identity)
            )
            return

        # Iterate over each uservariable
        uservars = []
        for key, val in uservars_dict.get('data', {}).items():

            if isinstance(val, dict) or isinstance(val, list):
                val = json.dumps(val, sort_keys=True)

            uservar = UservarEntity(
                environment=env.identity,
                name=key,
                value=val
            )
            uservar.update(session, self.time_in_ms)
            uservars.append(uservar)

        # Update edges
        env.uservars.update(session, uservars, self.time_in_ms)