예제 #1
0
  def Run(self, args):
    """Executes when the user runs the describe command."""
    conn_context = connection_context.GetConnectionContext(
        args, product=connection_context.Product.EVENTS)

    trigger_ref = args.CONCEPTS.trigger.Parse()
    with eventflow_operations.Connect(conn_context) as client:
      trigger_obj = client.GetTrigger(trigger_ref)
      source_obj = None
      if trigger_obj is not None:
        source_crds = client.ListSourceCustomResourceDefinitions()
        source_ref, source_crd = util.GetSourceRefAndCrdForTrigger(
            trigger_obj, source_crds)
        if source_ref and source_crd:
          source_obj = client.GetSource(source_ref, source_crd)

    if not trigger_obj:
      raise exceptions.TriggerNotFound(
          'Trigger [{}] not found.'.format(trigger_ref.Name()))
    if not source_obj:
      log.warning('No matching event source for trigger [{}].'.format(
          trigger_ref.Name()))
    return SerializedTriggerAndSource(
        trigger_obj.MakeSerializable(),
        source_obj.MakeSerializable() if source_obj else None)
예제 #2
0
    def Run(self, args):
        """Executes when the user runs the describe command."""
        conn_context = connection_context.GetConnectionContext(
            args, serverless_flags.Product.EVENTS, self.ReleaseTrack())

        trigger_ref = args.CONCEPTS.trigger.Parse()
        with eventflow_operations.Connect(conn_context) as client:
            if client.IsCluster():
                trigger_ref = resources.REGISTRY.Parse(
                    trigger_ref.RelativeName(),
                    collection=util.ANTHOS_TRIGGER_COLLECTION_NAME,
                    api_version=client.api_version)

            trigger_obj = client.GetTrigger(trigger_ref)
            source_obj = None
            if trigger_obj is not None:
                source_crds = client.ListSourceCustomResourceDefinitions()
                source_ref, source_crd = util.GetSourceRefAndCrdForTrigger(
                    trigger_obj, source_crds, client.IsCluster())
                if source_ref and source_crd:
                    source_obj = client.GetSource(source_ref, source_crd)

        if not trigger_obj:
            raise exceptions.TriggerNotFound('Trigger [{}] not found.'.format(
                trigger_ref.Name()))
        if not source_obj:
            log.warning('No matching event source for trigger [{}].'.format(
                trigger_ref.Name()))
        return SerializedTriggerAndSource(
            trigger_obj.MakeSerializable(),
            source_obj.MakeSerializable() if source_obj else None)
예제 #3
0
  def Run(self, args):
    """Executes when the user runs the delete command."""
    conn_context = connection_context.GetConnectionContext(
        args, serverless_flags.Product.EVENTS, self.ReleaseTrack())

    trigger_ref = args.CONCEPTS.trigger.Parse()
    console_io.PromptContinue(
        message='Trigger [{}] will be deleted.'.format(trigger_ref.Name()),
        throw_if_unattended=True,
        cancel_on_no=True)

    with eventflow_operations.Connect(conn_context) as client:
      # TODO(b/147308604): Don't delete source when Odin supports ownerRefs
      if serverless_flags.GetPlatform() == serverless_flags.PLATFORM_MANAGED:
        trigger_obj = client.GetTrigger(trigger_ref)
        if trigger_obj is not None:
          source_crds = client.ListSourceCustomResourceDefinitions()
          source_ref, source_crd = util.GetSourceRefAndCrdForTrigger(
              trigger_obj, source_crds)
          if source_ref and source_crd:
            # Delete the source before the trigger because we need the trigger
            # to exist to be able to find the source. Otherwise, we could end up
            # losing a reference to the source if trigger deletion succeeds but
            # source deletion fails.
            try:
              client.DeleteSource(source_ref, source_crd)
            except exceptions.SourceNotFound:
              # Source could have been deleted but trigger deletion failed
              # and this command was re-run, which is fine.
              pass
      client.DeleteTrigger(trigger_ref)

    log.DeletedResource(trigger_ref.Name(), 'trigger')
예제 #4
0
 def testGetSourceRefAndCrdForTrigger(self):
     self._MakeSourceCrds(num_sources=1, num_event_types_per_source=1)
     self._MakeSource(self.source_crds[0])
     self._MakeTrigger(self.source, self.event_types[0])
     expected = resources.REGISTRY.Parse(
         'source-for-my-trigger',
         params={'namespacesId': 'source-namespace'},
         collection='run.namespaces.cloudpubsubsources',
         api_version='v1alpha1')
     self.assertEqual(
         (expected, self.source_crds[0]),
         util.GetSourceRefAndCrdForTrigger(self.trigger, self.source_crds))