Ejemplo n.º 1
0
def send_to_workers(sender, *args, **kwargs):
    instance = kwargs['instance']
    if instance.base.state:
        distribute(
            SETTINGS_EVENT, json.dumps({instance.key: instance.value}),
            generate_vhost_configuration(instance.base.user.username,
                                         instance.base.name),
            instance.base.name, instance.base.executor.password)
Ejemplo n.º 2
0
 def _execute_async(self, request, request_data, base_model, rid):
     try:
         # _do on remote
         request_data.update({'rid': rid})
         call_rpc_client(json.dumps(request_data),
                         generate_vhost_configuration(
                             base_model.user.username, base_model.name),
                         base_model.name,
                         base_model.executor.password,
                         async=True)
     except Exception, e:
         logger.exception(e)
         raise e
Ejemplo n.º 3
0
    def _load(self):
        try:
            if not self.base_obj.state:
                raise Exception("Skipping because worker is not running")
            # try to load from installed module in worker
            logger.debug("%s: load from module in worker" % self.static_path)
            response_data = get_static(
                json.dumps({
                    "base_name": self.base_obj.name,
                    "path": self.static_path
                }),
                generate_vhost_configuration(self.base_obj.user.username,
                                             self.base_obj.name),
                self.base_obj.name, self.base_obj.executor.password)
            data = json.loads(response_data)

            if data['status'] == "ERROR":
                logger.error("%s: ERROR response from worker" %
                             self.static_path)
                raise Exception(response_data)
            elif data['status'] == "TIMEOUT":
                logger.error("%s: TIMEOT response from worker" %
                             self.static_path)
                raise Exception("Timeout")
            elif data['status'] == "OK":
                file = base64.b64decode(data['file'])
                last_modified = datetime.fromtimestamp(data['LM'])
                logger.debug(
                    "%s: file received from worker with timestamp: %s" %
                    (self.static_path, str(last_modified)))

                obj, created = StaticFile.objects.get_or_create(
                    base=self.base_obj, name=self.static_path, storage="MO")
                if obj.rev != data['LM'] or created:
                    obj.rev = data['LM']
                    obj.accessed = self.now
                    obj.save()

                file_obj = StorageStaticFile(username=self.username,
                                             project=self.project_name,
                                             name=self.static_name,
                                             content=file,
                                             last_modified=last_modified,
                                             storage=self.__class__.__name__,
                                             cached=True)
                return file_obj

        except Exception, e:
            logger.error(e)
            raise NotFound()
Ejemplo n.º 4
0
    def _execute(self, request, request_data, base_model, rid):
        try:
            # _do on remote
            start = int(round(time.time() * 1000))
            request_data.update({'rid': rid})
            response_data = call_rpc_client(
                json.dumps(request_data),
                generate_vhost_configuration(base_model.user.username,
                                             base_model.name), base_model.name,
                base_model.executor.password)
            end = int(round(time.time() * 1000))
            ms = str(end - start)

            logger.debug("DATA: %s" % str(response_data))

            logger.debug("RESPONSE-time: %sms" % str(ms))
            logger.debug("RESPONSE-data: %s" % response_data[:120])
            data = json.loads(response_data)
            data.update({
                "time_ms": ms,
            })
        except Exception, e:
            logger.exception(e)
            raise Exception("Could not execute request")
Ejemplo n.º 5
0
 def vhost(self):
     return generate_vhost_configuration(self.base.user.username,
                                         self.base.name)
Ejemplo n.º 6
0
        instance.save()

        # update app.config for saving description
        result = connection.put_file(
            "%s/%s/app.config" %
            (instance.base.user.username, instance.base.name),
            instance.base.config)
    except Exception, e:
        logger.exception(e)

    if instance.base.state:
        distribute(
            CONFIGURATION_EVENT, serializers.serialize("json", [
                instance,
            ]),
            generate_vhost_configuration(instance.base.user.username,
                                         instance.base.name),
            instance.base.name, instance.base.executor.password)


# Distribute signals
@receiver(post_save, sender=Setting)
def send_to_workers(sender, *args, **kwargs):
    instance = kwargs['instance']
    if instance.base.state:
        distribute(
            SETTINGS_EVENT, json.dumps({instance.key: instance.value}),
            generate_vhost_configuration(instance.base.user.username,
                                         instance.base.name),
            instance.base.name, instance.base.executor.password)

Ejemplo n.º 7
0
 def test_generate_vhost_configuration(self):
     from core.communication import generate_vhost_configuration
     vhost = generate_vhost_configuration('username', 'base1')
     self.assertEquals(vhost, "/username-base1")