-
Notifications
You must be signed in to change notification settings - Fork 57
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
Feature/656 device model initialization in cpp #681
Conversation
…thon. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…ion. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
… (install directory) so it can be copied to the target. Move sql script to separate 'migration' folder. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…raints, change foreign key of variable characteristics so we can add an ON DELETE constraint, which prevents dangling characteristics. Get components from db and check if they are in the schema, remove if they are not in the schema files but are existing in the database (only for Connectors and EVSE's). Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…eck if anything changed with components and variables and update variables. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…ributes, delete variables. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
… call so it also works with in memory databases. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…commented code. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
… so the value source is / can be set when an attribute value is changed. Add test for insert config and default values and fix some bugs. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
8637579
to
d9b5b0e
Compare
…me functions to not return a boolean, because they just throw if something is going wrong. Add more verbose information to exception. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
6b3e007
to
dbe1291
Compare
…d new tests. Fix almost all tests. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…ning when default value is an array or object). Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
f228821
to
e5a500c
Compare
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…ing foreign key pointing to it. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
… does not work anymore. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
return config_values; | ||
} | ||
|
||
bool InitDeviceModelDb::check_config_integrity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a check for the source of the value as well and add a log message if it is not 'default' (so the value is not changed)? And then maybe remove it from the list so we don't get more warnings about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like a good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm because it is now a vector, if there is any error in the vector it will throw. So maybe it is not the best idea after all :). I think I keep it like this.
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
52809d4
to
1fcf825
Compare
EVLOG_error << "Could not remove database " << database_path.u8string(); | ||
throw InitDeviceModelDbError("Could not remove database " + database_path.u8string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EVLOG_AND_THROW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it (and all the others). Shouldn't we use EVLOG_AND_THROW always instead of only throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say if you want to log an error that the user should see then yes, but if it's just an internal exception that can be handled without the user needed to know it's perfectly fine to just throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "errors" output variable should be handled in a different way (preferable with a return value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole string as return value you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, or a struct/vector with the individual errors might also be an idea
…port migrations yet. Fix some config / schema inconsistencies. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
a0216cd
to
9ea7186
Compare
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
9ea7186
to
654a121
Compare
…fault config value could not be set because it has already changed by another source. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…components / variables / attributes that are not consistent with the database. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
… at the check integrity function. Put inserting in database inside transactions, otherwise it is very slow. Add test for the default device model schemas / config. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
InitDeviceModelDbError("Config not consistent with device model component schema's: \n" + output)); | ||
} | ||
|
||
std::unique_ptr<common::DatabaseTransactionInterface> transaction = database->begin_transaction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting a transaction here and ending it at the end of the function. If anything throws in between, transaction will not be committed. I think that's the idea but I can of course also add a try/catch there. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and works well! Added a few remarks
MUTABILITY_ID INTEGER, | ||
PERSISTENT INTEGER, | ||
CONSTANT INTEGER, | ||
TYPE_ID INTEGER, | ||
VALUE_SOURCE TEXT DEFAULT "default", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to leave this empty and use config
for the initialization (by the config file) because its more verbose. There might be variables in the database without a value for the variable attribute
if (init_db) { | ||
if (db_path.empty() || migration_files_path.empty() || schemas_path.empty() || config_path.empty()) { | ||
EVLOG_AND_THROW( | ||
DeviceModelStorageError("Can not initialize device model storage: one of the paths is empty.")); | ||
} | ||
InitDeviceModelDb init_device_model_db(db_path, migration_files_path); | ||
init_device_model_db.initialize_database(schemas_path, false); | ||
init_device_model_db.insert_config_and_default_values(schemas_path, config_path); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also remove this constructor and move the content inside the ChargePoint constructor and leave the other DeviceModelStorageSqlite constructor as is.
I personally dont like a constructor that relies only on a certain combination of arguments to be valid. This would also avoid this odd initialzation L45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that constructor thing is a bit strange indeed
Problem is that I have to do the device model initialization before creating DeviceModelStorageSqlite.
I'll think about it (suggestions welcome)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the odd looking constructor and added default parameters to the remaining constructor. Because we do so much code in the constructors, I don't know how else to do it, because like I said the code has to be called before the code in the chargepoint constructor is called, which creates a device model instance. But all the migration and inserting stuff should have been done at that point already.
/// \param r Second componentKey to compare with the other ComponentKey | ||
/// \return True if 'l' is 'smaller' than r (should be placed before 'r'). | ||
/// | ||
friend bool operator<(const ComponentKey& l, const ComponentKey& r); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like using unordered_map(s) could be more suitable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I tried to change it but for an unordered_map you need a hash function.
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
…e and use default values. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
They should be fixed now. If possible. |
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
@@ -52,12 +52,6 @@ | |||
"Actual": true | |||
} | |||
}, | |||
"EVSEPower": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering why these variables were removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have been removed because they are not configuration but telemetry variables, so there is no reason to have them in the config.
…oes otherwise not work. Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
Signed-off-by: Piet Gömpel <[email protected]>
Describe your changes
Python script to initialize and insert device model database is now moved to C++. This also allows is to add more Connectors and EVSE's and change Variables of Connectors and EVSE's.
Not everything is done yet:
Issue ticket number and link
#656
Checklist before requesting a review