Ejemplo n.º 1
0
    def test_group_records(self):
        records = [{
            'site': 'chicago',
            'allocation': 'big',
            'name': 'sandwich'
        }, {
            'name': 'pizza',
            'allocation': 'big',
            'site': 'knoxville'
        }, {
            'name': 'burrito',
            'allocation': 'small',
            'site': 'chicago'
        }]

        groups = group_records(records, 'site')
        self.assertEqual(len(groups.keys()), 2)
        chicago = groups['chicago']
        self.assertTrue(isinstance(chicago, list))
        self.assertEqual(len(chicago), 2)
        self.assertEqual(len(groups['knoxville']), 1)

        groups = group_records(records, 'site', 'allocation')
        self.assertEqual(len(groups.keys()), 3)
        chicago_big = groups[('chicago', 'big')]
        self.assertEqual(chicago_big[0]['allocation'], 'big')
        self.assertEqual(chicago_big[0]['site'], 'chicago')
        for group in groups.itervalues():
            self.assertEqual(len(group), 1)
Ejemplo n.º 2
0
    def test_group_records(self):
        records = [
            {'site': 'chicago', 'allocation': 'big', 'name': 'sandwich'},
            {'name': 'pizza', 'allocation': 'big', 'site': 'knoxville'},
            {'name': 'burrito', 'allocation': 'small', 'site': 'chicago'}
        ]

        groups = group_records(records, 'site')
        self.assertEqual(len(groups.keys()), 2)
        chicago = groups['chicago']
        self.assertTrue(isinstance(chicago, list))
        self.assertEqual(len(chicago), 2)
        self.assertEqual(len(groups['knoxville']), 1)

        groups = group_records(records, 'site', 'allocation')
        self.assertEqual(len(groups.keys()), 3)
        chicago_big = groups[('chicago', 'big')]
        self.assertEqual(chicago_big[0]['allocation'], 'big')
        self.assertEqual(chicago_big[0]['site'], 'chicago')
        for group in groups.itervalues():
            self.assertEqual(len(group), 1)
Ejemplo n.º 3
0
    def query_nodes(self, request=None):
        """Performs queries of IaaS and broker, sends updates to subscribers.
        """
        # Right now we just query everything. Could be made more granular later

        nodes = yield self.store.get_nodes(max_state=states.TERMINATING)
        site_nodes = group_records(nodes, 'site')

        if len(nodes):
            log.debug("Querying state of %d nodes", len(nodes))

        for site in site_nodes:
            yield self.query_one_site(site, site_nodes[site])

        yield self.query_contexts()
Ejemplo n.º 4
0
 def mark_nodes_terminating(self, node_ids):
     """Mark a set of nodes as terminating in the data store
     """
     nodes = yield self._get_nodes_by_id(node_ids)
     log.debug("Marking nodes for termination: %s", node_ids)
     
     launches = group_records(nodes, 'launch_id')
     for launch_id, launch_nodes in launches.iteritems():
         launch = yield self.store.get_launch(launch_id)
         if not launch:
             log.warn('Failed to find launch record %s', launch_id)
             continue
         for node in launch_nodes:
             if node['state'] < states.TERMINATING:
                 node['state'] = states.TERMINATING
         yield self.store_and_notify(launch_nodes, launch['subscribers'])
Ejemplo n.º 5
0
            yield self.store_and_notify(nodes, launch['subscribers'])

    @defer.inlineCallbacks
    def _really_execute_provision_request(self, launch, nodes):
        """Brings a launch to the PENDING state.
        """
        subscribers = launch['subscribers']
        docstr = launch['document']
        context = launch['context']

        try:
            doc = NimbusClusterDocument(docstr)
        except ValidationError, e:
            raise ProvisioningError('CONTEXT_DOC_INVALID '+str(e))

        launch_groups = group_records(nodes, 'ctx_name')

        specs = doc.build_specs(context)

        # we want to fail early, before we launch anything if possible
        launch_pairs = self._validate_launch_groups(launch_groups, specs)

        has_failed = False
        #launch_pairs is a list of (spec, node list) tuples
        for launch_spec, launch_nodes in launch_pairs:

            # for recovery case
            if not any(node['state'] < states.PENDING for node in launch_nodes):
                log.info('Skipping launch group %s -- all nodes started',
                         launch_spec.name)
                continue