Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop column transport_params from the Computer database model #2946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (c), The AiiDA team. All rights reserved. #
# This file is part of the AiiDA code. #
# #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
# pylint: disable=invalid-name,too-few-public-methods
"""Drop the `transport_params` from the `Computer` database model."""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import

# Remove when https://github.com/PyCQA/pylint/issues/1931 is fixed
# pylint: disable=no-name-in-module,import-error,no-member
from django.db import migrations

from aiida.backends.djsite.db.migrations import upgrade_schema_version

REVISION = '1.0.36'
DOWN_REVISION = '1.0.35'


class Migration(migrations.Migration):
"""Drop the `transport_params` from the `Computer` database model."""

dependencies = [
('db', '0035_simplify_user_model'),
]

operations = [
migrations.RemoveField(
model_name='dbcomputer',
name='transport_params',
),
upgrade_schema_version(REVISION, DOWN_REVISION)
]
2 changes: 1 addition & 1 deletion aiida/backends/djsite/db/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DeserializationException(AiidaException):
pass


LATEST_MIGRATION = '0035_simplify_user_model'
LATEST_MIGRATION = '0036_drop_computer_transport_params'


def _update_schema_version(version, apps, schema_editor):
Expand Down
3 changes: 1 addition & 2 deletions aiida/backends/djsite/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,8 @@ class DbComputer(m.Model):
hostname = m.CharField(max_length=255)
description = m.TextField(blank=True)
# TODO: next three fields should not be blank...
transport_type = m.CharField(max_length=255)
scheduler_type = m.CharField(max_length=255)
transport_params = JSONField(default=dict)
transport_type = m.CharField(max_length=255)
metadata = JSONField(default=dict)

def __str__(self):
Expand Down
3 changes: 0 additions & 3 deletions aiida/backends/djsite/db/subtests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,11 @@ def setUpBeforeMigration(self):
self.node.save()

self.computer_metadata = {'shebang': '#!/bin/bash', 'workdir': '/scratch/', 'append_text': '', 'prepend_text': '', 'mpirun_command': ['mpirun', '-np', '{tot_num_mpiprocs}'], 'default_mpiprocs_per_machine': 1}
self.computer_transport_params = {'append_text': 'sometext\ntest', 'max_machines': 1}
self.computer_kwargs = {
'name': 'localhost_testing',
'hostname': 'localhost',
'transport_type': 'local',
'scheduler_type': 'direct',
'transport_params': json.dumps(self.computer_transport_params),
'metadata': json.dumps(self.computer_metadata),
}
self.computer = self.DbComputer(**self.computer_kwargs)
Expand Down Expand Up @@ -790,7 +788,6 @@ def test_text_field_to_json_field_migration(self):

# Make sure that the migrated data matches the original
self.assertDictEqual(computer.metadata, self.computer_metadata)
self.assertDictEqual(computer.transport_params, self.computer_transport_params)
self.assertDictEqual(auth_info.metadata, self.auth_info_metadata)
self.assertDictEqual(auth_info.auth_params, self.auth_info_auth_params)
self.assertDictEqual(log.metadata, self.log_metadata)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (c), The AiiDA team. All rights reserved. #
# This file is part of the AiiDA code. #
# #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
"""Drop the `transport_params` from the `Computer` database model.

Revision ID: 61fc0913fae9
Revises: ce56d84bcc35
Create Date: 2019-02-16 15:32:42.745450

"""
# pylint: disable=invalid-name,no-member,import-error,no-name-in-module
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '07fac78e6209'
down_revision = 'de2eaf6978b4'
branch_labels = None
depends_on = None


def upgrade():
"""Migrations for the upgrade."""
op.drop_column('db_dbcomputer', 'transport_params')


def downgrade():
"""Migrations for the downgrade."""
op.add_column(
'db_dbcomputer',
sa.Column('transport_params', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True))
4 changes: 1 addition & 3 deletions aiida/backends/sqlalchemy/models/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ class DbComputer(Base):
name = Column(String(255), unique=True, nullable=False)
hostname = Column(String(255))
description = Column(Text, nullable=True)
transport_type = Column(String(255))
scheduler_type = Column(String(255))
transport_params = Column(JSONB)
transport_type = Column(String(255))
_metadata = Column('metadata', JSONB)

def __init__(self, *args, **kwargs):
self._metadata = {}
self.transport_params = {}
# TODO SP: it's supposed to be nullable, but there is a NOT constraint inside the DB.
self.description = ""

Expand Down
Binary file modified aiida/backends/tests/fixtures/calcjob/arithmetic.add_old.aiida
Binary file not shown.
29 changes: 6 additions & 23 deletions aiida/backends/tests/test_export_and_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,28 +1230,21 @@ def test_different_computer_same_name_import(self, temp_dir):
@with_temp_dir
def test_correct_import_of_computer_json_params(self, temp_dir):
"""
This test checks that the metadata and transport params are
exported and imported correctly in both backends.
This test checks that the metadata is exported and imported correctly in both backends.
"""
# Set the computer name
comp1_name = "localhost_1"
comp1_metadata = {
u'workdir': u'/tmp/aiida'
}
comp1_transport_params = {
u'key1': u'value1',
u'key2': 2
}
self.computer.set_name(comp1_name)
self.computer.set_metadata(comp1_metadata)
self.computer.set_transport_params(comp1_transport_params)

# Store a calculation
calc1_label = "calc1"
calc1 = orm.CalcJobNode()
calc1.computer = self.computer
calc1.set_option('resources', {"num_machines": 1,
"num_mpiprocs_per_machine": 1})
calc1.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
calc1.label = calc1_label
calc1.store()

Expand All @@ -1265,15 +1258,10 @@ def test_correct_import_of_computer_json_params(self, temp_dir):
import_data(filename1, silent=True)

builder = orm.QueryBuilder()
builder.append(orm.Computer, project=['transport_params', '_metadata'],
tag="comp")
builder.append(orm.Computer, project=['_metadata'], tag="comp")
self.assertEqual(builder.count(), 1, "Expected only one computer")

res = builder.dict()[0]
self.assertEqual(res['comp']['transport_params'],
comp1_transport_params,
"Not the expected transport parameters "
"were found")
self.assertEqual(res['comp']['_metadata'],
comp1_metadata,
"Not the expected metadata were found")
Expand All @@ -1290,25 +1278,20 @@ def test_import_of_django_sqla_export_file(self):
# Import the needed data
import_archive_fixture(archive)

# The expected metadata & transport parameters
# The expected metadata
comp1_metadata = {
u'workdir': u'/tmp/aiida'
}
comp1_transport_params = {
u'key1': u'value1',
u'key2': 2
}

# Check that we got the correct metadata & transport parameters
# Check that we got the correct metadata
# Make sure to exclude the default computer
builder = orm.QueryBuilder()
builder.append(orm.Computer, project=['transport_params', '_metadata'], tag="comp",
builder.append(orm.Computer, project=['_metadata'], tag="comp",
filters={'name': {'!==': self.computer.name}})
self.assertEqual(builder.count(), 1, "Expected only one computer")

res = builder.dict()[0]

self.assertEqual(res['comp']['transport_params'], comp1_transport_params)
self.assertEqual(res['comp']['_metadata'], comp1_metadata)


Expand Down
9 changes: 1 addition & 8 deletions aiida/backends/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ class TestQueryBuilderCornerCases(AiidaTestCase):
def test_computer_json(self): # pylint: disable=no-self-use
"""
In this test we check the correct behavior of QueryBuilder when
retrieving the _metadata and the transport_params with no content.
retrieving the _metadata with no content.
Note that they are in JSON format in both backends. Forcing the
decoding of a None value leads to an exception (this was the case
under Django).
Expand All @@ -610,13 +610,6 @@ def test_computer_json(self): # pylint: disable=no-self-use
n1.set_attribute('foo', 1)
n1.store()

# Checking the correct retrieval of transport_params which is
# a JSON field (in both backends).
qb = orm.QueryBuilder()
qb.append(orm.CalculationNode, project=['id'], tag='calc')
qb.append(orm.Computer, project=['id', 'transport_params'], outerjoin=True, with_node='calc')
qb.all()

# Checking the correct retrieval of _metadata which is
# a JSON field (in both backends).
qb = orm.QueryBuilder()
Expand Down
5 changes: 1 addition & 4 deletions aiida/orm/authinfos.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,11 @@ def get_transport(self):
"""
computer = self.computer
transport_type = computer.get_transport_type()
transport_params = computer.get_transport_params()

try:
transport_class = TransportFactory(transport_type)
except exceptions.EntryPointError as exception:
raise exceptions.ConfigurationError('transport type `{}` could not be loaded: {}'.format(
transport_type, exception))

parameters = dict(list(transport_params.items()) + list(self.get_auth_params().items()))

return transport_class(machine=computer.hostname, **parameters)
return transport_class(machine=computer.hostname, **self.get_auth_params())
14 changes: 1 addition & 13 deletions aiida/orm/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def validate(self):
try:
mpirun_cmd = self.get_mpirun_command()
except exceptions.DbContentError:
raise exceptions.ValidationError("Error in the DB content of the transport_params")
raise exceptions.ValidationError("Error in the DB content of the metadata")

# To be called AFTER the validation of the scheduler
self._mpirun_command_validator(mpirun_cmd)
Expand Down Expand Up @@ -442,12 +442,6 @@ def set_minimum_job_poll_interval(self, interval):
"""
self.set_property(self.PROPERTY_MINIMUM_SCHEDULER_POLL_INTERVAL, interval)

def get_transport_params(self):
return self._backend_entity.get_transport_params()

def set_transport_params(self, val):
self._backend_entity.set_transport_params(val)

def get_transport(self, user=None):
"""
Return a Transport class, configured with all correct parameters.
Expand Down Expand Up @@ -761,12 +755,6 @@ def get_schema():
}
}
},
"transport_params": {
"display_name": "",
"help_text": "Transport Parameters",
"is_foreign_key": False,
"type": "str"
},
"transport_type": {
"display_name": "Transport type",
"help_text": "Transport Type",
Expand Down
8 changes: 0 additions & 8 deletions aiida/orm/implementation/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ def set_metadata(self, metadata):
times, differently from AiiDA Node objects).
"""

@abc.abstractmethod
def get_transport_params(self):
pass

@abc.abstractmethod
def set_transport_params(self, val):
pass

@abc.abstractmethod
def get_name(self):
pass
Expand Down
6 changes: 0 additions & 6 deletions aiida/orm/implementation/django/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ def get_metadata(self):
def set_metadata(self, metadata):
self._dbmodel.metadata = metadata

def get_transport_params(self):
return self._dbmodel.transport_params

def set_transport_params(self, val):
self._dbmodel.transport_params = val

def get_name(self):
return self._dbmodel.name

Expand Down
1 change: 0 additions & 1 deletion aiida/orm/implementation/django/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def _(dbmodel, backend):
description=dbmodel.description,
transport_type=dbmodel.transport_type,
scheduler_type=dbmodel.scheduler_type,
transport_params=dbmodel.transport_params,
metadata=dbmodel._metadata) # pylint: disable=protected-access
return computers.DjangoComputer.from_dbmodel(djcomputer_instance, backend)

Expand Down
3 changes: 1 addition & 2 deletions aiida/orm/implementation/django/dummy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ class DbComputer(Base):

description = Column(Text, nullable=True)

transport_type = Column(String(255))
scheduler_type = Column(String(255))
transport_type = Column(String(255))

transport_params = Column(String(255))
_metadata = Column('metadata', String(255), default="{}")


Expand Down
15 changes: 1 addition & 14 deletions aiida/orm/implementation/sqlalchemy/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from aiida.backends.sqlalchemy import get_scoped_session
from aiida.backends.sqlalchemy.models.computer import DbComputer
from aiida.common import exceptions, json
from aiida.common import exceptions
from aiida.orm.implementation.computers import BackendComputerCollection, BackendComputer

from . import utils
Expand Down Expand Up @@ -97,19 +97,6 @@ def get_metadata(self):
def set_metadata(self, metadata):
self._dbmodel._metadata = metadata # pylint: disable=protected-access

def get_transport_params(self):
"""
Return transport params stored in dbcomputer instance
"""
return self._dbmodel.transport_params

def set_transport_params(self, val):
try:
json.dumps(val) # Check if json compatible
self._dbmodel.transport_params = val
except ValueError:
raise ValueError("The set of transport_params are not JSON-able")

def get_name(self):
return self._dbmodel.name

Expand Down
5 changes: 0 additions & 5 deletions aiida/orm/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def get_all_fields_info():
}
all_fields_info[COMPUTER_ENTITY_NAME] = {
"transport_type": {},
"transport_params": {},
"hostname": {},
"description": {},
"scheduler_type": {},
Expand Down Expand Up @@ -1497,10 +1496,6 @@ def import_data_sqla(in_path, user_group=None, ignore_unknown_nodes=False,
isinstance(v['metadata'], six.binary_type)):
v['metadata'] = json.loads(v['metadata']) # loads() can handle str and unicode/bytes

if (isinstance(v['transport_params'], six.string_types) or
isinstance(v['transport_params'], six.binary_type)):
v['transport_params'] = json.loads(v['transport_params'])

# Check if there is already a computer with the
# same name in the database
qb = QueryBuilder()
Expand Down
Loading