예제 #1
0
    def validate_workspace(self, name, json_config):
        """Validates a new workspace prior to attempting a save

        :param name: The identifying name of a Workspace to validate
        :type name: string
        :param json_config: The Workspace configuration
        :type json_config: dict
        :returns: A list of warnings discovered during validation.
        :rtype: list[:class:`storage.configuration.workspace_configuration.ValidationWarning`]

        :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid
        """
        warnings = []

        # Validate the configuration, no exception is success
        config = WorkspaceConfiguration(json_config)

        # Check for issues when changing an existing workspace configuration
        try:
            workspace = Workspace.objects.get(name=name)

            if (json_config['broker'] and workspace.json_config['broker'] and
                    json_config['broker']['type'] != workspace.json_config['broker']['type']):
                warnings.append(ValidationWarning('broker_type',
                                                  'Changing the broker type may disrupt queued/running jobs.'))
        except Workspace.DoesNotExist:
            pass

        # Add broker-specific warnings
        warnings.extend(config.validate_broker())
        return warnings
예제 #2
0
파일: models.py 프로젝트: AppliedIS/scale
    def validate_workspace(self, name, json_config):
        """Validates a new workspace prior to attempting a save

        :param name: The identifying name of a Workspace to validate
        :type name: string
        :param json_config: The Workspace configuration
        :type json_config: dict
        :returns: A list of warnings discovered during validation.
        :rtype: list[:class:`storage.configuration.workspace_configuration.ValidationWarning`]

        :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid
        """
        warnings = []

        # Validate the configuration, no exception is success
        config = WorkspaceConfiguration(json_config)

        # Check for issues when changing an existing workspace configuration
        try:
            workspace = Workspace.objects.get(name=name)

            if (json_config['broker'] and workspace.json_config['broker'] and
                    json_config['broker']['type'] != workspace.json_config['broker']['type']):
                warnings.append(ValidationWarning('broker_type',
                                                  'Changing the broker type may disrupt queued/running jobs.'))
        except Workspace.DoesNotExist:
            pass

        # Add broker-specific warnings
        warnings.extend(config.validate_broker())
        return warnings
예제 #3
0
    def get_configuration(self):
        """Returns the workspace configuration represented by this JSON

        :returns: The workspace configuration
        :rtype: :class:`workspace.configuration.workspace_configuration.WorkspaceConfiguration`:
        """

        config = WorkspaceConfiguration()
        config.configuration = self._config

        return config
    def test_successful(self):
        """Tests calling WorkspaceConfiguration constructor successfully with all information."""

        # No exception is success
        config = WorkspaceConfiguration({
            'broker': {
                'type': 'host',
                'host_path': '/host/path',
            },
        })
        config.validate_broker()
    def test_bare_min(self):
        """Tests calling WorkspaceConfiguration constructor with bare minimum JSON."""

        # No exception is success
        config = WorkspaceConfiguration({
            'broker': {
                'type': 'host',
                'host_path': '/the/path',
            },
        })
        config.validate_broker()
예제 #6
0
    def test_successful(self):
        """Tests calling WorkspaceConfiguration constructor successfully with all information."""

        # No exception is success
        config = WorkspaceConfiguration({
            'broker': {
                'type': 'host',
                'host_path': '/host/path',
            },
        })
        config.validate_broker()
예제 #7
0
    def test_bare_min(self):
        """Tests calling WorkspaceConfiguration constructor with bare minimum JSON."""

        # No exception is success
        config = WorkspaceConfiguration({
            'broker': {
                'type': 'host',
                'host_path': '/the/path',
            },
        })
        config.validate_broker()
예제 #8
0
파일: models.py 프로젝트: AppliedIS/scale
    def get_broker(self):
        """Returns the configured broker for this workspace

        :returns: The configured broker
        :rtype: :class:`storage.brokers.broker.Broker`
        """

        if not hasattr(self, '_broker'):
            ws_config = WorkspaceConfiguration(self.json_config)
            ws_config.validate_broker()

            broker_config = self.json_config['broker']
            broker_type = broker_config['type']
            broker = get_broker(broker_type)
            broker.load_configuration(broker_config)
            self._broker = broker
        return self._broker
예제 #9
0
    def get_broker(self):
        """Returns the configured broker for this workspace

        :returns: The configured broker
        :rtype: :class:`storage.brokers.broker.Broker`
        """

        if not hasattr(self, '_broker'):
            ws_config = WorkspaceConfiguration(self.json_config)
            ws_config.validate_broker()

            broker_config = self.json_config['broker']
            broker_type = broker_config['type']
            broker = get_broker(broker_type)
            broker.load_configuration(broker_config)
            self._broker = broker
        return self._broker
예제 #10
0
    def test_scale_delete_files(self, mock_message, mock_delete):
        """Tests calling Scale to delete files"""
        def new_delete(files, volume_path, broker):
            return

        mock_delete.side_effect = new_delete

        config = WorkspaceConfiguration(self.workspace.json_config)

        files_str = '-f {"file_path":"/dir/file.name", "id":"12300", "workspace":"workspace_1"}'
        workspace_str = '-w {"workspace_1": %s}' % (config.get_dict())
        purge_str = '-p False'

        with self.assertRaises(SystemExit):
            django.core.management.call_command('scale_delete_files',
                                                files_str, workspace_str,
                                                purge_str)
예제 #11
0
    def edit_workspace(self,
                       workspace_id,
                       title=None,
                       description=None,
                       json_config=None,
                       base_url=None,
                       is_active=None):
        """Edits the given Workspace and saves the changes in the database. All database changes occur in an atomic
        transaction. An argument of None for a field indicates that the field should not change.

        :param workspace_id: The unique identifier of the Workspace to edit
        :type workspace_id: int
        :param title: The human-readable name of this Workspace
        :type title: string
        :param description: A description of this Workspace
        :type description: string
        :param json_config: The Workspace configuration
        :type json_config: dict
        :param base_url: The URL prefix used to download files stored in the Workspace.
        :type base_url: string
        :param is_active: Whether or not the Workspace is available for use.
        :type is_active: bool

        :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid
        """

        workspace = Workspace.objects.get(pk=workspace_id)

        # Validate the configuration, no exception is success
        if json_config:
            config = WorkspaceConfiguration(json_config)
            config.validate_broker()
            workspace.json_config = config.get_dict()

        # Update editable fields
        if title:
            workspace.title = title
        if description:
            workspace.description = description
        if base_url:
            workspace.base_url = base_url
        if is_active is not None:
            workspace.is_active = is_active
        workspace.save()
예제 #12
0
    def test_bad_host_config(self):
        """Tests calling WorkspaceConfiguration constructor with bad host broker configuration."""

        config = WorkspaceConfiguration({
            'broker': {
                'type': 'host',
            },
        })
        self.assertRaises(InvalidWorkspaceConfiguration,
                          config.validate_broker)
예제 #13
0
    def create_workspace(self,
                         name,
                         title,
                         description,
                         json_config,
                         base_url=None,
                         is_active=True):
        """Creates a new Workspace with the given configuration and returns the new Workspace model.
        The Workspace model will be saved in the database and all changes to the database will occur in an atomic
        transaction.

        :param name: The identifying name of this Workspace
        :type name: string
        :param title: The human-readable name of this Workspace
        :type title: string
        :param description: A description of this Workspace
        :type description: string
        :param json_config: The Workspace configuration
        :type json_config: dict
        :param base_url: The URL prefix used to download files stored in the Workspace.
        :type base_url: string
        :param is_active: Whether or not the Workspace is available for use.
        :type is_active: bool
        :returns: The new Workspace
        :rtype: :class:`storage.models.Workspace`

        :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid
        """

        # Validate the configuration, no exception is success
        config = WorkspaceConfiguration(json_config)
        config.validate_broker()

        workspace = Workspace()
        workspace.name = name
        workspace.title = title
        workspace.description = description
        workspace.json_config = config.get_dict()
        workspace.base_url = base_url
        workspace.is_active = is_active
        workspace.save()
        return workspace
예제 #14
0
파일: models.py 프로젝트: AppliedIS/scale
    def edit_workspace(self, workspace_id, title=None, description=None, json_config=None, base_url=None,
                       is_active=None):
        """Edits the given Workspace and saves the changes in the database. All database changes occur in an atomic
        transaction. An argument of None for a field indicates that the field should not change.

        :param workspace_id: The unique identifier of the Workspace to edit
        :type workspace_id: int
        :param title: The human-readable name of this Workspace
        :type title: string
        :param description: A description of this Workspace
        :type description: string
        :param json_config: The Workspace configuration
        :type json_config: dict
        :param base_url: The URL prefix used to download files stored in the Workspace.
        :type base_url: string
        :param is_active: Whether or not the Workspace is available for use.
        :type is_active: bool

        :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid
        """

        workspace = Workspace.objects.get(pk=workspace_id)

        # Validate the configuration, no exception is success
        if json_config:
            config = WorkspaceConfiguration(json_config)
            config.validate_broker()
            workspace.json_config = config.get_dict()

        # Update editable fields
        if title:
            workspace.title = title
        if description:
            workspace.description = description
        if base_url:
            workspace.base_url = base_url
        if is_active is not None:
            workspace.is_active = is_active
        workspace.save()
예제 #15
0
    def _detect_workspaces(self, workspace_list):
        """Parses, validates, and returns workspace information for the given workspaces

        :param workspace_list: The workspace list that was given
        :type workspace_list: [dict]
        :return: All workspaces by given name with associated broker and volume_path
        :rtype: dict
        """

        workspaces = {}
        for workspace in workspace_list:
            name = workspace.keys()[0]
            wrkspc = WorkspaceConfiguration(workspace[name])
            wrkspc.validate_broker()
            valid_wrkspc = wrkspc.get_dict()

            workspaces[name] = {
                'broker': get_broker(valid_wrkspc['broker']['type']),
                'volume_path': valid_wrkspc['broker']['host_path']
            }

        return workspaces
예제 #16
0
파일: models.py 프로젝트: AppliedIS/scale
    def create_workspace(self, name, title, description, json_config, base_url=None, is_active=True):
        """Creates a new Workspace with the given configuration and returns the new Workspace model.
        The Workspace model will be saved in the database and all changes to the database will occur in an atomic
        transaction.

        :param name: The identifying name of this Workspace
        :type name: string
        :param title: The human-readable name of this Workspace
        :type title: string
        :param description: A description of this Workspace
        :type description: string
        :param json_config: The Workspace configuration
        :type json_config: dict
        :param base_url: The URL prefix used to download files stored in the Workspace.
        :type base_url: string
        :param is_active: Whether or not the Workspace is available for use.
        :type is_active: bool
        :returns: The new Workspace
        :rtype: :class:`storage.models.Workspace`

        :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid
        """

        # Validate the configuration, no exception is success
        config = WorkspaceConfiguration(json_config)
        config.validate_broker()

        workspace = Workspace()
        workspace.name = name
        workspace.title = title
        workspace.description = description
        workspace.json_config = config.get_dict()
        workspace.base_url = base_url
        workspace.is_active = is_active
        workspace.save()
        return workspace