Пример #1
0
def change_directory(current_folder, path):
    """Change directory"""
    if path == '..':
        return current_folder[0:current_folder.rindex('/')]
    if path == '':
        return util.get_properties('rootFolder')
    return current_folder + '/' + path
Пример #2
0
    def setup_producer(self):
        if self.instance_config.function_details.sink.topic != None and \
                len(self.instance_config.function_details.sink.topic) > 0:
            Log.debug("Setting up producer for topic %s" %
                      self.instance_config.function_details.sink.topic)

            batch_type = pulsar.BatchingType.Default
            if self.instance_config.function_details.sink.producerSpec.batchBuilder != None and \
                  len(self.instance_config.function_details.sink.producerSpec.batchBuilder) > 0:
                batch_builder = self.instance_config.function_details.sink.producerSpec.batchBuilder
                if batch_builder == "KEY_BASED":
                    batch_type = pulsar.BatchingType.KeyBased

            self.producer = self.pulsar_client.create_producer(
                str(self.instance_config.function_details.sink.topic),
                block_if_queue_full=True,
                batching_enabled=True,
                batching_type=batch_type,
                batching_max_publish_delay_ms=10,
                compression_type=pulsar.CompressionType.LZ4,
                # set send timeout to be infinity to prevent potential deadlock with consumer
                # that might happen when consumer is blocked due to unacked messages
                send_timeout_millis=0,
                properties=util.get_properties(
                    util.getFullyQualifiedFunctionName(
                        self.instance_config.function_details.tenant,
                        self.instance_config.function_details.namespace,
                        self.instance_config.function_details.name),
                    self.instance_config.instance_id))
Пример #3
0
  def publish(self, topic_name, message, serde_class_name="serde.IdentitySerDe", properties=None, compression_type=None, callback=None):
    # Just make sure that user supplied values are properly typed
    topic_name = str(topic_name)
    serde_class_name = str(serde_class_name)
    pulsar_compression_type = pulsar._pulsar.CompressionType.NONE
    if compression_type is not None:
      pulsar_compression_type = compression_type
    if topic_name not in self.publish_producers:
      self.publish_producers[topic_name] = self.pulsar_client.create_producer(
        topic_name,
        block_if_queue_full=True,
        batching_enabled=True,
        batching_max_publish_delay_ms=10,
        compression_type=pulsar_compression_type,
        properties=util.get_properties(util.getFullyQualifiedFunctionName(
          self.instance_config.function_details.tenant,
          self.instance_config.function_details.namespace,
          self.instance_config.function_details.name),
          self.instance_config.instance_id)
      )

    if serde_class_name not in self.publish_serializers:
      serde_klass = util.import_class(self.user_code_dir, serde_class_name)
      self.publish_serializers[serde_class_name] = serde_klass()

    output_bytes = bytes(self.publish_serializers[serde_class_name].serialize(message))
    self.publish_producers[topic_name].send_async(output_bytes, partial(self.callback_wrapper, callback, topic_name, self.get_message_id()), properties=properties)
Пример #4
0
def update_fields(service_id):
    properties = get_properties(service_id)
    if not properties.keys():
        return

    if get_value(properties, "AutoConnect") == "true":
        autoconn = "Yes"
    else:
        autoconn = "No"
    form.get('autoconnect').value = autoconn

    form.get('nameservers').value = get_str_value(properties,
                                                  "Nameservers.Configuration")
    form.get('timeservers').value = get_str_value(properties,
                                                  "Timeservers.Configuration")
    form.get('domains').value = get_str_value(properties,
                                              "Domains.Configuration")
    value = get_dict_value(properties, "Proxy.Configuration", "Method")
    if value == "":
        value = "auto"
    form.get('proxymethod').value = value
    form.get('proxyurl').value = get_dict_value(properties,
                                                "Proxy.Configuration", "URL")
    form.get('proxyservers').value = get_dict_value(properties,
                                                    "Proxy.Configuration",
                                                    "Servers")
    form.get('proxyexcludes').value = get_dict_value(properties,
                                                     "Proxy.Configuration",
                                                     "Excludes")
    form.get('ipv4method').value = get_dict_value(properties,
                                                   "IPv4.Configuration",
                                                   "Method")
    form.get('ipv4address').value = get_dict_value(properties,
                                                   "IPv4.Configuration",
                                                   "Address")
    form.get('ipv4netmask').value = get_dict_value(properties,
                                                   "IPv4.Configuration",
                                                   "Netmask")
    form.get('ipv4gateway').value = get_dict_value(properties,
                                                   "IPv4.Configuration",
                                                   "Gateway")
    form.get('ipv6method').value = get_dict_value(properties,
                                                   "IPv6.Configuration",
                                                   "Method")
    form.get('ipv6address').value = get_dict_value(properties,
                                                   "IPv6.Configuration",
                                                   "Address")
    value = get_dict_value(properties, "IPv6.Configuration",
                           "PrefixLength")
    if value != "":
        value = "%d" % value
    form.get('ipv6prefixlen').value = value
    form.get('ipv6gateway').value = get_dict_value(properties,
                                                   "IPv6.Configuration",
                                                   "Gateway")
    form.get('ipv6privacy').value = get_dict_value(properties,
                                                   "IPv6.Configuration",
                                                   "Privacy")
Пример #5
0
def update_fields(service_id):
    properties = get_properties(service_id)
    if not properties.keys():
        return

    if get_value(properties, "AutoConnect") == "true":
        autoconn = "Yes"
    else:
        autoconn = "No"
    form.get('autoconnect').value = autoconn

    form.get('nameservers').value = get_str_value(properties,
                                                  "Nameservers.Configuration")
    form.get('timeservers').value = get_str_value(properties,
                                                  "Timeservers.Configuration")
    form.get('domains').value = get_str_value(properties,
                                              "Domains.Configuration")
    value = get_dict_value(properties, "Proxy.Configuration", "Method")
    if value == "":
        value = "auto"
    form.get('proxymethod').value = value
    form.get('proxyurl').value = get_dict_value(properties,
                                                "Proxy.Configuration", "URL")
    form.get('proxyservers').value = get_dict_value(properties,
                                                    "Proxy.Configuration",
                                                    "Servers")
    form.get('proxyexcludes').value = get_dict_value(properties,
                                                     "Proxy.Configuration",
                                                     "Excludes")
    form.get('ipv4method').value = get_dict_value(properties,
                                                  "IPv4.Configuration",
                                                  "Method")
    form.get('ipv4address').value = get_dict_value(properties,
                                                   "IPv4.Configuration",
                                                   "Address")
    form.get('ipv4netmask').value = get_dict_value(properties,
                                                   "IPv4.Configuration",
                                                   "Netmask")
    form.get('ipv4gateway').value = get_dict_value(properties,
                                                   "IPv4.Configuration",
                                                   "Gateway")
    form.get('ipv6method').value = get_dict_value(properties,
                                                  "IPv6.Configuration",
                                                  "Method")
    form.get('ipv6address').value = get_dict_value(properties,
                                                   "IPv6.Configuration",
                                                   "Address")
    value = get_dict_value(properties, "IPv6.Configuration", "PrefixLength")
    if value != "":
        value = "%d" % value
    form.get('ipv6prefixlen').value = value
    form.get('ipv6gateway').value = get_dict_value(properties,
                                                   "IPv6.Configuration",
                                                   "Gateway")
    form.get('ipv6privacy').value = get_dict_value(properties,
                                                   "IPv6.Configuration",
                                                   "Privacy")
Пример #6
0
  def setup_producer(self):
    if self.instance_config.function_details.sink.topic != None and \
            len(self.instance_config.function_details.sink.topic) > 0:
      Log.debug("Setting up producer for topic %s" % self.instance_config.function_details.sink.topic)

      self.producer = self.pulsar_client.create_producer(
        str(self.instance_config.function_details.sink.topic),
        block_if_queue_full=True,
        batching_enabled=True,
        batching_max_publish_delay_ms=1,
        # set send timeout to be infinity to prevent potential deadlock with consumer
        # that might happen when consumer is blocked due to unacked messages
        send_timeout_millis=0,
        max_pending_messages=100000,
        properties=util.get_properties(util.getFullyQualifiedFunctionName(
                        self.instance_config.function_details.tenant,
                        self.instance_config.function_details.namespace,
                        self.instance_config.function_details.name),
                        self.instance_config.instance_id)
      )
Пример #7
0
    def run(self):
        # Setup state
        self.state_context = self.setup_state()

        # Setup consumers and input deserializers
        mode = pulsar._pulsar.ConsumerType.Shared
        if self.instance_config.function_details.source.subscriptionType == Function_pb2.SubscriptionType.Value(
                "FAILOVER"):
            mode = pulsar._pulsar.ConsumerType.Failover

        subscription_name = str(self.instance_config.function_details.tenant) + "/" + \
                            str(self.instance_config.function_details.namespace) + "/" + \
                            str(self.instance_config.function_details.name)

        properties = util.get_properties(
            util.getFullyQualifiedFunctionName(
                self.instance_config.function_details.tenant,
                self.instance_config.function_details.namespace,
                self.instance_config.function_details.name),
            self.instance_config.instance_id)

        for topic, serde in self.instance_config.function_details.source.topicsToSerDeClassName.items(
        ):
            if not serde:
                serde_kclass = util.import_class(
                    os.path.dirname(self.user_code), DEFAULT_SERIALIZER)
            else:
                serde_kclass = util.import_class(
                    os.path.dirname(self.user_code), serde)
            self.input_serdes[topic] = serde_kclass()
            Log.debug("Setting up consumer for topic %s with subname %s" %
                      (topic, subscription_name))

            self.consumers[topic] = self.pulsar_client.subscribe(
                str(topic),
                subscription_name,
                consumer_type=mode,
                message_listener=partial(self.message_listener,
                                         self.input_serdes[topic]),
                unacked_messages_timeout_ms=int(self.timeout_ms)
                if self.timeout_ms else None,
                properties=properties)

        for topic, consumer_conf in self.instance_config.function_details.source.inputSpecs.items(
        ):
            if not consumer_conf.serdeClassName:
                serde_kclass = util.import_class(
                    os.path.dirname(self.user_code), DEFAULT_SERIALIZER)
            else:
                serde_kclass = util.import_class(
                    os.path.dirname(self.user_code),
                    consumer_conf.serdeClassName)
            self.input_serdes[topic] = serde_kclass()
            Log.debug("Setting up consumer for topic %s with subname %s" %
                      (topic, subscription_name))

            consumer_args = {
                "consumer_type":
                mode,
                "message_listener":
                partial(self.message_listener, self.input_serdes[topic]),
                "unacked_messages_timeout_ms":
                int(self.timeout_ms) if self.timeout_ms else None,
                "properties":
                properties
            }
            if consumer_conf.HasField("receiverQueueSize"):
                consumer_args[
                    "receiver_queue_size"] = consumer_conf.receiverQueueSize.value

            if consumer_conf.isRegexPattern:
                self.consumers[topic] = self.pulsar_client.subscribe(
                    re.compile(str(topic)), subscription_name, **consumer_args)
            else:
                self.consumers[topic] = self.pulsar_client.subscribe(
                    str(topic), subscription_name, **consumer_args)

        function_kclass = util.import_class(
            os.path.dirname(self.user_code),
            self.instance_config.function_details.className)
        if function_kclass is None:
            Log.critical("Could not import User Function Module %s" %
                         self.instance_config.function_details.className)
            raise NameError("Could not import User Function Module %s" %
                            self.instance_config.function_details.className)
        try:
            self.function_class = function_kclass()
        except:
            self.function_purefunction = function_kclass

        self.contextimpl = contextimpl.ContextImpl(
            self.instance_config, Log, self.pulsar_client, self.user_code,
            self.consumers, self.secrets_provider, self.metrics_labels,
            self.state_context, self.stats)
        # Now launch a thread that does execution
        self.execution_thread = threading.Thread(target=self.actual_execution)
        self.execution_thread.start()

        # start proccess spawner health check timer
        self.last_health_check_ts = time.time()
        if self.expected_healthcheck_interval > 0:
            timer = util.FixedTimer(self.expected_healthcheck_interval,
                                    self.process_spawner_health_check_timer,
                                    name="health-check-timer")
            timer.start()
Пример #8
0
def update_service(input, service_id):
    properties = get_properties(service_id)
    if not properties.keys():
        return "No properties for service %s" % service_id

    service = get_service(service_id)

    try:
        if input.autoconnect == "Yes":
            autoconnect = True
        else:
            autoconnect = False
        (value_changed, error) = change(service, properties, "AutoConnect",
                                        autoconnect)
        if not value_changed:
            return service_not_found(service_id, error, "AutoConnect")
    except:
        pass

    try:
        (value_changed, error) = change(service, properties,
                                        "Domains.Configuration",
                                        input.domains,
                                        dbus.Array([input.domains],
                                                signature=dbus.Signature('s')))
        if not value_changed:
            return service_not_found(service_id, error, "Domains")
    except:
        pass

    try:
        (value_changed, error) = change(service, properties,
                                        "Nameservers.Configuration",
                                        input.nameservers,
                                        dbus.Array([input.nameservers],
                                               signature=dbus.Signature('s')))
        if not value_changed:
            return service_not_found(service_id, error, "Nameservers")
    except:
        pass

    try:
        (value_changed, error) = change(service, properties,
                                        "Timeservers.Configuration",
                                        input.timeservers,
                                        dbus.Array([input.timeservers],
                                               signature=dbus.Signature('s')))
        if not value_changed:
            return service_not_found(service_id, error, "Timeservers")
    except:
        pass

    try:
        if input.proxymethod == "auto":
            if changed_dict(properties, "Proxy.Configuration", "URL",
                            input.proxyurl):
                proxy = { "Method": make_variant("auto") }
                proxy["URL"] = make_variant(input.proxyurl)
                try:
                    service.SetProperty("Proxy.Configuration", proxy)
                except dbus.DBusException, error:
                    return service_not_found(service_id, error,
                                             "Proxy URL setting failed")

        elif input.proxymethod == "manual":
            set_property = False
            proxy = { "Method": make_variant("manual") }
            if changed_dict(properties, "Proxy.Configuration", "Servers",
                            input.proxyservers):
                proxy["Servers"] = split_string(input.proxyservers)
                set_property = True

            if changed_dict(properties, "Proxy.Configuration", "Excludes",
                        input.proxyexcludes):
                proxy["Excludes"] = split_string(input.proxyexcludes)
                set_property = True

            if set_property:
                try:
                    service.SetProperty("Proxy.Configuration",
                                        dbus.Dictionary(proxy, signature='sv'))
                except dbus.DBusException, error:
                    return service_not_found(service_id, error,
                                             "Manual Proxy setting failed")
Пример #9
0
#!/usr/bin/python
"""Main script"""

import cmd
import util

root_folder = util.get_properties('rootFolder')

current_folder = root_folder

user = util.get_properties('userName')

args = ['']

while args[0] != 'exit':
    util.print_greetings(user, current_folder)
    args = raw_input().lower().split()
    print 'Entered: %s' % args[0]
    if args[0] == 'ls':
        cmd.list_files(current_folder)
    elif args[0] == 'cd':
        current_folder = cmd.change_directory(current_folder, args[1])
    elif args[0] == 'cp':
        cmd.copy(current_folder + '/' + args[1], root_folder + '/' + args[2])
    elif args[0] == 'mv':
        cmd.move_file(args[1], args[2])
    # elif args[0] == 'rm':
    # elif args[0] == 'mkdir':
    elif args[0] == 'exit':
        print 'Goodbye!'
    else:
Пример #10
0
def update_service(input, service_id):
    properties = get_properties(service_id)
    if not properties.keys():
        return "No properties for service %s" % service_id

    service = get_service(service_id)

    try:
        if input.autoconnect == "Yes":
            autoconnect = True
        else:
            autoconnect = False
        (value_changed, error) = change(service, properties, "AutoConnect",
                                        autoconnect)
        if not value_changed:
            return service_not_found(service_id, error, "AutoConnect")
    except:
        pass

    try:
        (value_changed, error) = change(
            service, properties, "Domains.Configuration", input.domains,
            dbus.Array([input.domains], signature=dbus.Signature('s')))
        if not value_changed:
            return service_not_found(service_id, error, "Domains")
    except:
        pass

    try:
        (value_changed, error) = change(
            service, properties, "Nameservers.Configuration",
            input.nameservers,
            dbus.Array([input.nameservers], signature=dbus.Signature('s')))
        if not value_changed:
            return service_not_found(service_id, error, "Nameservers")
    except:
        pass

    try:
        (value_changed, error) = change(
            service, properties, "Timeservers.Configuration",
            input.timeservers,
            dbus.Array([input.timeservers], signature=dbus.Signature('s')))
        if not value_changed:
            return service_not_found(service_id, error, "Timeservers")
    except:
        pass

    try:
        if input.proxymethod == "auto":
            if changed_dict(properties, "Proxy.Configuration", "URL",
                            input.proxyurl):
                proxy = {"Method": make_variant("auto")}
                proxy["URL"] = make_variant(input.proxyurl)
                try:
                    service.SetProperty("Proxy.Configuration", proxy)
                except dbus.DBusException, error:
                    return service_not_found(service_id, error,
                                             "Proxy URL setting failed")

        elif input.proxymethod == "manual":
            set_property = False
            proxy = {"Method": make_variant("manual")}
            if changed_dict(properties, "Proxy.Configuration", "Servers",
                            input.proxyservers):
                proxy["Servers"] = split_string(input.proxyservers)
                set_property = True

            if changed_dict(properties, "Proxy.Configuration", "Excludes",
                            input.proxyexcludes):
                proxy["Excludes"] = split_string(input.proxyexcludes)
                set_property = True

            if set_property:
                try:
                    service.SetProperty("Proxy.Configuration",
                                        dbus.Dictionary(proxy, signature='sv'))
                except dbus.DBusException, error:
                    return service_not_found(service_id, error,
                                             "Manual Proxy setting failed")