Beispiel #1
0
    def _start_task(self, context):
        run_opts = {
            'cluster': self.cluster,
            'taskDefinition': self.task_definition,
            'overrides': self.overrides,
            'startedBy': self.owner,
        }

        if self.capacity_provider_strategy:
            run_opts[
                'capacityProviderStrategy'] = self.capacity_provider_strategy
            run_opts['platformVersion'] = self.platform_version
        elif self.launch_type:
            run_opts['launchType'] = self.launch_type
            if self.launch_type == 'FARGATE':
                run_opts['platformVersion'] = self.platform_version
        if self.group is not None:
            run_opts['group'] = self.group
        if self.placement_constraints is not None:
            run_opts['placementConstraints'] = self.placement_constraints
        if self.placement_strategy is not None:
            run_opts['placementStrategy'] = self.placement_strategy
        if self.network_configuration is not None:
            run_opts['networkConfiguration'] = self.network_configuration
        if self.tags is not None:
            run_opts['tags'] = [{
                'key': k,
                'value': v
            } for (k, v) in self.tags.items()]
        if self.propagate_tags is not None:
            run_opts['propagateTags'] = self.propagate_tags

        response = self.client.run_task(**run_opts)

        failures = response['failures']
        if len(failures) > 0:
            raise ECSOperatorError(failures, response)
        self.log.info('ECS Task started: %s', response)

        self.arn = response['tasks'][0]['taskArn']
        ecs_task_id = self.arn.split("/")[-1]
        self.log.info(f"ECS task ID is: {ecs_task_id}")

        if self.reattach:
            # Save the task ARN in XCom to be able to reattach it if needed
            self._xcom_set(
                context,
                key=self.REATTACH_XCOM_KEY,
                value=self.arn,
                task_id=self.REATTACH_XCOM_TASK_ID_TEMPLATE.format(
                    task_id=self.task_id),
            )
Beispiel #2
0
    def _start_task(self):
        run_opts = {
            'cluster': self.cluster,
            'taskDefinition': self.task_definition,
            'overrides': self.overrides,
            'startedBy': self.owner,
        }

        if self.capacity_provider_strategy:
            run_opts[
                'capacityProviderStrategy'] = self.capacity_provider_strategy
            run_opts['platformVersion'] = self.platform_version
        elif self.launch_type:
            run_opts['launchType'] = self.launch_type
            if self.launch_type == 'FARGATE':
                run_opts['platformVersion'] = self.platform_version
        if self.group is not None:
            run_opts['group'] = self.group
        if self.placement_constraints is not None:
            run_opts['placementConstraints'] = self.placement_constraints
        if self.placement_strategy is not None:
            run_opts['placementStrategy'] = self.placement_strategy
        if self.network_configuration is not None:
            run_opts['networkConfiguration'] = self.network_configuration
        if self.tags is not None:
            run_opts['tags'] = [{
                'key': k,
                'value': v
            } for (k, v) in self.tags.items()]
        if self.propagate_tags is not None:
            run_opts['propagateTags'] = self.propagate_tags

        response = self.client.run_task(**run_opts)

        failures = response['failures']
        if len(failures) > 0:
            raise ECSOperatorError(failures, response)
        self.log.info('ECS Task started: %s', response)

        self.arn = response['tasks'][0]['taskArn']
Beispiel #3
0
 def test_return_false_on_invalid_reason(self):
     self.assertFalse(
         should_retry(
             ECSOperatorError([{
                 'reason': 'CLUSTER_NOT_FOUND'
             }], 'Foo')))
Beispiel #4
0
 def test_return_true_on_valid_reason(self):
     self.assertTrue(
         should_retry(
             ECSOperatorError([{
                 'reason': 'RESOURCE:MEMORY'
             }], 'Foo')))