Save for the weekend.

This commit is contained in:
Gerhard Hoffmann 2023-10-20 13:55:18 +02:00
parent 29e6a25e72
commit 81c5f8ee7e
10 changed files with 581 additions and 259 deletions

View File

@ -41,6 +41,9 @@ DEFINES += QT_DEPRECATED_WARNINGS
# up cloning of customer repository.
# 1.3.13: Fix: if the customer repository is corrupted, remove it and re-clone
# the repository (without checking the ISMAS-trigger (WAIT-)button.
# 1.3.14: Add additional check for sanity of customer repository using
# "git fsck".
# Stream-lined code of update process.
win32 {
BUILD_DATE=$$system("date /t")

View File

@ -279,6 +279,17 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
return std::nullopt;
}
bool GitClient::gitFsck() {
bool r = false;
if (QDir(m_customerRepository).exists()) {
Command c("git fsck");
if ((r = c.execute(m_customerRepository)) == false) {
QString const &s = c.getCommandResult().trimmed();
Utils::printCriticalErrorMsg(QString("GIT FSCK FAILED: %1").arg(s));
}
}
return r;
}
/*
Hat sich nichts geaendert, so werden auch keine Commits <>..<> angezeigt
*/

View File

@ -47,6 +47,8 @@ class GitClient : public QObject {
std::optional<QStringList> gitDiff(QString const &commit);
std::optional<QStringList> gitMerge();
bool gitFsck();
QString gitLastCommit(QString fileName);
QStringList gitShowReason(QString branchName);
static QString gitBlob(QString fileName);

View File

@ -390,16 +390,18 @@ QString IsmasClient::errorBackendNotConnected(QString const &info,
version.toStdString().c_str());
}
QString IsmasClient::errorGitClone(int percent, QString const &info, QString const &version) {
QString IsmasClient::errorGitClone(QString const &info,
QString const &version) {
return updateNewsToIsmas("U0003",
percent,
m_progressInPercent,
RESULT_CODE::INSTALL_ERROR,
"CLONE CUSTOMER REPOSITORY FAILED",
info.toStdString().c_str(),
version.toStdString().c_str());
}
QString IsmasClient::backendConnected(QString const &info, QString const &version) {
QString IsmasClient::backendConnected(QString const &info,
QString const &version) {
return updateNewsToIsmas("U0010",
m_progressInPercent,
RESULT_CODE::SUCCESS,
@ -408,7 +410,8 @@ QString IsmasClient::backendConnected(QString const &info, QString const &versio
version.toStdString().c_str());
}
QString IsmasClient::execOpkgCommand(QString const &info, QString const &version) {
QString IsmasClient::execOpkgCommand(QString const &info,
QString const &version) {
return updateNewsToIsmas("U0010",
m_progressInPercent,
RESULT_CODE::SUCCESS,

View File

@ -177,7 +177,7 @@ public:
QString cloneAndCheckoutCustomerRepository(QString const &info, QString const &version = QString()); // clone and checkout customer repository
QString checkoutBranch(QString const &info, QString const &version = QString()); // checkout branch
QString errorBackendNotConnected(QString const &info, QString const &version = QString()); // checkout branch
QString errorGitClone(int percent, QString const &info, QString const &version = QString());
QString errorGitClone(QString const &info, QString const &version = QString());
QString backendConnected(QString const &info, QString const &version = QString());
QString updateTriggerSet(QString const &info, QString const &version = QString());
QString errorUpdateTrigger(QString const &info, QString const &version = QString());

View File

@ -96,7 +96,7 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren
, m_worker(worker)
, m_width(70)
, m_progressRunning(false)
, m_progressValue(0)
// , m_progressValue(0)
, m_update(update)
, m_updateStep(UpdateDcEvent::UpdateStep::NONE) {
@ -178,22 +178,22 @@ void MainWindow::customEvent(QEvent *event) {
case START_PROGRESS_LOOP: {
m_progressRunning = true;
ui->updateProgress->reset();
m_progressValue = 10;
QApplication::postEvent(this, new ProgressEvent(this, m_progressValue));
// m_progressValue = 10;
QApplication::postEvent(this, new ProgressEvent(this, 1));
} break;
case STOP_PROGRESS_LOOP: {
m_progressRunning = false;
m_progressValue -= 10;
m_worker->setProgress(m_progressValue/10);
// m_progressValue -= 10;
// m_worker->setProgress(m_progressValue/10);
} break;
default: {
if (m_progressRunning) {
m_progressValue = progress;
ui->updateProgress->setValue(progress/10);
QApplication::postEvent(this, new ProgressEvent(this, progress+10));
QThread::msleep(500);
}
}
// m_progressValue = progress;
ui->updateProgress->setValue(progress);
// ueberpruefen: hauptfenster schickt sich selber ein event
// QApplication::postEvent(this, new ProgressEvent(this, progress));
// QThread::msleep(500);
}}
}
} else
if (sender == m_worker) {

View File

@ -34,7 +34,7 @@ public:
static const int BL_IS_UP_COUNT = 5;
static const int BL_STOP_COUNT = 5;
int progressValue() const { return m_progressValue; }
// int progressValue() const { return m_progressValue; }
hwinf *getPlugin() { return m_hw; }
hwinf const *getPlugin() const { return m_hw; }
Update *getUpdate() { return m_update; }
@ -76,7 +76,7 @@ private:
QTimer *m_startTimer;
QTimer *m_exitTimer;
bool m_progressRunning;
int m_progressValue;
//int m_progressValue;
Update *m_update;
UpdateDcEvent::UpdateStep m_updateStep;
};

View File

@ -846,8 +846,8 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
res = false;
}
m_worker->stopProgressLoop();
m_worker->setProgress(100);
// m_worker->stopProgressLoop();
// m_worker->setProgress(100);
if (res == false) {
break;

View File

@ -17,8 +17,6 @@
#include <QJsonParseError>
#include <Qt>
#include <thread>
#include "message_handler.h"
#include "plugins/interfaces.h"
#include "ismas/ismas_client.h"
@ -31,6 +29,8 @@ QString const Worker::UPDATE_STEP_DONE(" [done]");
QString const Worker::UPDATE_STEP_FAIL(" [FAIL]");
QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]");
Worker const *Worker::instance = nullptr;
Worker::Worker(int customerNr,
int machineNr,
int zoneNr,
@ -73,10 +73,12 @@ Worker::Worker(int customerNr,
, m_updateProcessRunning(true)
, m_returnCode(0)
, m_mainWindow(nullptr) /* contains plugin */
, m_progressValue(0)
//, m_withoutIsmasDirectPort(true) /* useful for testing */ {
, m_withoutIsmasDirectPort(false) /* useful for testing */ {
// TODO: turn object into singleton
instance = this;
this->setObjectName("worker-object");
QDir::setCurrent(m_workingDirectory);
@ -127,19 +129,25 @@ Worker::~Worker() {
}
}
void Worker::setProgress(int progress) {
void Worker::displayProgressInMainWindow(int progress) {
if (m_mainWindow) {
m_progressValue = progress;
QApplication::postEvent(m_mainWindow, new ProgressEvent(this, progress));
QApplication::postEvent(m_mainWindow,
new ProgressEvent(this, progress));
}
}
void Worker::setProgress(int progress) {
m_ismasClient.setProgressInPercent(progress);
displayProgressInMainWindow(progress);
}
void Worker::startProgressLoop() {
QApplication::postEvent(m_mainWindow, new ProgressEvent(this, MainWindow::START_PROGRESS_LOOP));
displayProgressInMainWindow(MainWindow::START_PROGRESS_LOOP);
}
void Worker::stopProgressLoop() {
QApplication::postEvent(m_mainWindow, new ProgressEvent(this, MainWindow::STOP_PROGRESS_LOOP));
displayProgressInMainWindow(MainWindow::STOP_PROGRESS_LOOP);
}
static std::once_flag once;
@ -154,9 +162,10 @@ bool Worker::isRepositoryCorrupted() {
QDir customerRepositoryEtc(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/"));
QDir customerRepositoryOpt(QDir::cleanPath(m_customerRepository + QDir::separator() + "opt/"));
QDir customerRepositoryGit(QDir::cleanPath(m_customerRepository + QDir::separator() + ".git/"));
if (!m_gc.gitFsck()
// etc-directory inside git-repository does not exist, which means the
// git-repository is corrupted -> remove it and start from scratch
if (!customerRepositoryEtc.exists()
|| !customerRepositoryEtc.exists()
|| !customerRepositoryGit.exists()
|| !customerRepositoryOpt.exists()) {
// should never happen
@ -164,7 +173,6 @@ bool Worker::isRepositoryCorrupted() {
return true;
}
}
return false;
}
@ -182,17 +190,14 @@ bool Worker::repairCorruptedRepository() {
return false;
}
return true;
}
int Worker::sendCloneAndCheckoutFailure() {
stopProgressLoop();
setProgress(0);
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE,
QString("CLONE OR CHECKOUT FAILED: ") + m_customerRepository);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.errorGitClone(100, m_updateStatus.m_statusDescription));
m_ismasClient.errorGitClone(m_updateStatus.m_statusDescription));
return CLONE_AND_CHECKOUT_FAILURE;
}
@ -212,8 +217,6 @@ int Worker::sendCloneAndCheckoutSuccess() {
}
int Worker::sendIsmasTriggerFailure() {
stopProgressLoop();
setProgress(0);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET_FAILURE,
QString("ISMAS update trigger wrong"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -224,6 +227,172 @@ int Worker::sendIsmasTriggerFailure() {
return ISMAS_TRIGGER_FAILURE;
}
int Worker::sendCustomerEnvironmentConfigurationFailed() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE,
QString("Configuring customer environment failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"GIT-CHECKOUT-BRANCH",
m_updateStatus.m_statusDescription));
return ENVIRONMENT_CONFIG_FAILURE;
}
int Worker::sendPullFailure() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
QString("No files to update"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"FETCH-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
return GIT_PULL_FAILURE;
}
int Worker::sendFileUpdateFailure() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED,
QString("Updating files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"UPDATE-FILES",
m_updateStatus.m_statusDescription));
return UPDATE_FILES_FAILURE;
}
int Worker::sendRsyncFailure() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE,
QString("Syncing files to update failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"RSYNC-UPDATE-FILES",
m_updateStatus.m_statusDescription));
return RSYNC_FAILURE;
}
int Worker::sendLastVersionFailure() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED,
QString("Sending ISMAS last version failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"ISMAS-SEND-LAST-VERSION",
m_updateStatus.m_statusDescription));
return SEND_LAST_VERSION_FAILURE;
}
int Worker::sendSaveLogFilesFailure() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED,
QString("Saving log files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"SAVE-LOG-FILES",
m_updateStatus.m_statusDescription));
return SAVE_LOG_FILES_FAILURE;
}
int Worker::sendFoundFilesToUpdateSuccess() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
QString("Files to update: ") + m_filesToUpdate.join(','));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
return 0;
}
int Worker::sendUpdateSucceededAndActivated() {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
//m_ismasClient.setProgressInPercent(100);
// mark update as activated -> this resets the WAIT button
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
return UPDATE_SUCCESS_AND_ACTIVATED;
}
int Worker::sendFinalResult() {
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_SUCCESS,
QString("Update process succeeded. Reset WAIT."));
if (std::optional<QString> s = m_ismasClient.finalResult(IsmasClient::RESULT_CODE::SUCCESS,
m_updateStatus.m_statusDescription)) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + s.value());
}
return 0;
}
#if 0
void Worker::printProgress(UPDATE_STEP step) {
switch(step) {
case UPDATE_STEP::SANITY_CHECK:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 1: CHECKED SANITY OF CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 2: FETCH CUSTOMER REPOSITORY %1...")
.arg(m_customerRepository));
break;
case UPDATE_STEP::FETCH_REPOSITORY:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 3: CHECK ISMAS-UPDATE-TRIGGER FOR WAIT-STATUS..."));
break;
case UPDATE_STEP::CHECK_ISMAS_TRIGGER:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 3: CHECKED ISMAS-UPDATE-TRIGGER FOR WAIT-STATUS. SUCCESS.")
<< QString("STEP 4: CHECK-OUT BRANCH %1...").arg(m_gc.branchName()));
break;
case UPDATE_STEP::CHECKED_OUT_BRANCH:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 4: CHECKED-OUT BRANCH %1 DONE")
.arg(m_gc.branchName())
<< QString("STEP 5: COMPUTE FILES-TO-UPDATE..."));
break;
case UPDATE_STEP::COMPUTE_FILES_TO_UPDATE:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 5: COMPUTE FILES-TO-UPDATE %1 DONE")
.arg(m_filesToUpdate.join(','))
<< QString("STEP 6: DOWNLOAD FILES-TO-DOWNLOAD %1 AND EXECUTE OPKG_COMMANDS...")
.arg(m_filesToDownload.join(',')));
break;
case UPDATE_STEP::DOWNLOAD_FILES_TO_UPDATE:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 6: DOWNLOAD FILES-TO-DOWNLOAD %1 AND EXECUTE OPKG_COMMANDS DONE")
.arg(m_filesToDownload.join(','))
<< QString("STEP 7: SYNC CUSTOMER REPOSITORY %1 WITH FILESYSTEM...")
.arg(m_customerRepository));
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 7: SYNC CUSTOMER REPOSITORY %1 WITH FILESYSTEM DONE")
.arg(m_customerRepository)
<< QString("STEP 8: SEND-LAST-VERSION TO ISMAS..."));
break;
case UPDATE_STEP::UPDATE_SUCCESS:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 9: SAVE-LOG-FILES (FUTURE USE) DONE")
<< QString("STEP 10: MARK UPDATE AS SUCCESSFUL AND ACTIVE..."));
break;
}
}
#endif
void Worker::privateUpdate() {
if (!m_mainWindow) {
@ -269,14 +438,7 @@ void Worker::privateUpdate() {
}
if (continueUpdate) {
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 1: CHECKED SANITY OF CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 2: FETCH CUSTOMER REPOSITORY %1...")
.arg(m_customerRepository));
// qDebug() << UPDATE_STEP::SANITY_CHECK;
if ((continueUpdate = customerRepository.exists()) == false) {
emit appendText("\nInitializing customer environment ...");
startProgressLoop();
@ -292,7 +454,6 @@ void Worker::privateUpdate() {
break;
}
}
QThread::sleep(1); // maybe git needs more time
}
if (continueUpdate == false) {
@ -300,154 +461,79 @@ void Worker::privateUpdate() {
m_returnCode = sendCloneAndCheckoutFailure();
}
}
}
if (continueUpdate) { // repository is neither not existent nor
// corrupted. check now if the ISMAS-trigger
// (WAIT-BUTTON) is activated even in case of
// initial checkout
if (!initialClone) {
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 3: CHECK ISMAS-UPDATE-TRIGGER FOR WAIT-STATUS..."));
//if ((continueUpdate = updateTriggerSet(10)) == false) {
// m_returnCode = sendIsmasTriggerFailure();
//}
if (updateTriggerSet(10)) {
if (customerEnvironment(30)) {
m_ismasClient.setProgressInPercent(50);
if (filesToUpdate()) {
// send message to ISMAS about files which have been
// checked in into git repository
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
QString("Files to update: ") + m_filesToUpdate.join(','));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
if (updateFiles(60)) {
m_ismasClient.setProgressInPercent(70);
if (syncCustomerRepositoryAndFS()) {
m_ismasClient.setProgressInPercent(80);
if (sendIsmasLastVersionNotification()) {
m_ismasClient.setProgressInPercent(90);
sentIsmasLastVersionNotification = true;
if (saveLogFile()) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
// mark update as activated -> this resets the WAIT button
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
// qDebug() << UPDATE_STEP::FETCH_REPOSITORY;
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED,
QString("Saving log files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"SAVE-LOG-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -11;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED,
QString("Sending ISMAS last version failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"ISMAS-SEND-LAST-VERSION",
m_updateStatus.m_statusDescription));
m_returnCode = -10;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE,
QString("Syncing files to update failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"RSYNC-UPDATE-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -9;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED,
QString("Updating files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"UPDATE-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -8;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
QString("No files to update"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"FETCH-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
m_returnCode = -7;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE,
QString("Configuring customer environment failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"GIT-CHECKOUT-BRANCH",
m_updateStatus.m_statusDescription));
m_returnCode = -6;
}
} else {
m_returnCode = sendIsmasTriggerFailure();
}
} else { // initialClone
Utils::printUpdateStatusMsg(
QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository));
} // repository is neither not existent nor
} // corrupted. check now if the ISMAS-trigger
if (continueUpdate) { // (WAIT-BUTTON) is activated even in case of
// initial checkout
if ((continueUpdate = updateTriggerSet(10)) == false) {
m_returnCode = sendIsmasTriggerFailure();
}
if (continueUpdate) { // configure customer environment -> checkout
// branch in case someone has change the zone_nr
//qDebug() << UPDATE_STEP::CHECK_ISMAS_TRIGGER;
if ((continueUpdate = customerEnvironment(30)) == false) {
m_returnCode = sendCustomerEnvironmentConfigurationFailed();
} // determine which files has to be updated:
} // either sent to the hardware or rsynced with
if (continueUpdate) { // the filesystem in case of tariff-files
//qDebug() << UPDATE_STEP::CHECKED_OUT_BRANCH;
if ((continueUpdate = filesToUpdate(50)) == false) {
m_returnCode = sendPullFailure();
}
} // send message to ISMAS about files which have
if (continueUpdate) { // been checked in into git repository
//qDebug() << UPDATE_STEP::COMPUTE_FILES_TO_UPDATE;
sendFoundFilesToUpdateSuccess();
if ((continueUpdate = updateFiles(60)) == false) {
m_returnCode = sendFileUpdateFailure();
}
}
if (continueUpdate) { // rsync (changed) files to file system
//qDebug() << UPDATE_STEP::DOWNLOAD_FILES_TO_UPDATE;
// TODO: rsync das komplette repository
if ((continueUpdate = syncCustomerRepositoryAndFS(70)) == false) {
m_returnCode = sendRsyncFailure();
}
}
if (continueUpdate) { // send message to ISMAS about installed versions
//qDebug() << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY;
if ((continueUpdate = sendIsmasLastVersionNotification(80)) == false) {
m_returnCode = sendLastVersionFailure();
}
}
if (continueUpdate) { // future use: save logs of update process
sentIsmasLastVersionNotification = true;
if ((continueUpdate = saveLogFile(90)) == false) {
m_returnCode = sendSaveLogFilesFailure();
}
} // send message to ISMAS that update process
if (continueUpdate) { // succeeded
//qDebug() << UPDATE_STEP::UPDATE_SUCCESS;
sendUpdateSucceededAndActivated();
m_returnCode = UPDATE_SUCCESS_AND_ACTIVATED;
}
m_ismasClient.setProgressInPercent(100);
setProgress(100);
if (m_returnCode != 0) {
stopProgressLoop();
emit appendText(QString("UPDATE "), UPDATE_STEP_FAIL);
// m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_FAILURE,
// QString("Update process failed"));
// if (std::optional<QString> s = m_ismasClient.finalResult(IsmasClient::RESULT_CODE::INSTALL_ERROR,
// m_updateStatus.m_statusDescription)) {
// IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
// QString("#M=APISM#C=CMD_EVENT#J=") + s.value());
// }
} else {
emit appendText(QString("UPDATE "), UPDATE_STEP_SUCCESS);
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_SUCCESS,
QString("Update process succeeded. Reset WAIT."));
if (std::optional<QString> s = m_ismasClient.finalResult(IsmasClient::RESULT_CODE::SUCCESS,
m_updateStatus.m_statusDescription)) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + s.value());
sendFinalResult();
}
}
if (!sentIsmasLastVersionNotification) {
// try even if the backend is not connected
sendIsmasLastVersionNotification();
sendIsmasLastVersionNotification(100);
}
m_updateProcessRunning = false;
@ -551,7 +637,7 @@ bool Worker::updateTriggerSet(int progress) {
= IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
stopProgressLoop();
setProgress(m_mainWindow->progressValue()/10 + 11);
// setProgress(m_mainWindow->progressValue()/10 + 11);
QString msg = result.value();
@ -562,7 +648,7 @@ bool Worker::updateTriggerSet(int progress) {
if (parseError.error != QJsonParseError::NoError) {
qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):"
<< parseError.error << parseError.errorString();
setProgress(100);
//setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE,
QString("(2) INVALID JSON %1 %2 %3")
.arg(msg)
@ -579,7 +665,7 @@ bool Worker::updateTriggerSet(int progress) {
}
if (!document.isObject()) {
qCritical() << "FILE IS NOT A JSON OBJECT!";
setProgress(100);
//setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE,
QString("NOT A JSON-OBJECT %1").arg(msg));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -590,13 +676,13 @@ bool Worker::updateTriggerSet(int progress) {
emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL);
return false;
}
setProgress(m_mainWindow->progressValue()/10 + 11);
// setProgress(m_mainWindow->progressValue()/10 + 11);
QJsonObject obj = document.object();
// always look for an 'error' first
if (obj.contains("error")) {
setProgress(m_mainWindow->progressValue()/10 + 11);
// setProgress(m_mainWindow->progressValue()/10 + 11);
QString value = obj.value("error").toString();
emit showErrorMessage("check update trigger", QString("REPEAT %1 error=<").arg(repeat) + value + ">");
qInfo() << "REPEAT" << repeat << "In updateTriggerSet() error=<"
@ -617,7 +703,7 @@ bool Worker::updateTriggerSet(int progress) {
int customerNr = c.toInt(-1);
int machineNr = m.toInt(-1);
if (customerNr != m_customerNr) {
setProgress(100);
//setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)")
.arg(customerNr).arg(m_customerNr));
@ -630,7 +716,6 @@ bool Worker::updateTriggerSet(int progress) {
return false;
}
if (machineNr != m_machineNr) {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)")
.arg(machineNr).arg(m_machineNr));
@ -646,7 +731,6 @@ bool Worker::updateTriggerSet(int progress) {
qInfo() << "MACHINE-AND-CUSTOMER-CHECK" << m_updateStatus.m_statusDescription;
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Dev_ID DOES NOT CONTAIN Custom_ID AND/OR Device_ID");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -658,7 +742,6 @@ bool Worker::updateTriggerSet(int progress) {
return false;
}
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Dev_ID KEY NOT A JSON-OBJECT");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -670,7 +753,6 @@ bool Worker::updateTriggerSet(int progress) {
return false;
}
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Dev_ID KEY NOT AVAILABLE");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -681,7 +763,7 @@ bool Worker::updateTriggerSet(int progress) {
emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL);
return false;
}
setProgress(m_mainWindow->progressValue()/10 + 11);
// setProgress(m_mainWindow->progressValue()/10 + 11);
if (obj.contains("Fileupload")) {
QJsonValue v = obj.value("Fileupload");
@ -695,7 +777,6 @@ bool Worker::updateTriggerSet(int progress) {
<< triggerValue << ">";
if (triggerValue == "WAIT") {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SANITY_CHECK_OK,
QString("MACHINE-NR (%1) AND CUST-NR (%2) OK")
.arg(m_machineNr).arg(m_customerNr));
@ -721,13 +802,12 @@ bool Worker::updateTriggerSet(int progress) {
} else
if (QRegExp("\\s*").exactMatch(triggerValue)) { // check for whitespace
stopProgressLoop();
setProgress(m_mainWindow->progressValue()/10 + 11);
// setProgress(m_mainWindow->progressValue()/10 + 11);
emit showErrorMessage("check update trigger", "empty update-trigger");
QThread::sleep(6);
continue;
} else {
// if the download-button once has the wrong value, it will never recover
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
QString("TRIGGER-VALUE=<") + triggerValue + "> NOT 'WAIT'");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -739,7 +819,6 @@ bool Worker::updateTriggerSet(int progress) {
return false;
}
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"TRG KEY NOT AVAILABLE");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -751,7 +830,6 @@ bool Worker::updateTriggerSet(int progress) {
return false;
}
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Fileupload NOT A JSON-OBJECT");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -763,7 +841,6 @@ bool Worker::updateTriggerSet(int progress) {
return false;
}
} else {
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE,
"Fileupload KEY NOT AVAILABLE");
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -776,13 +853,12 @@ bool Worker::updateTriggerSet(int progress) {
}
} else {
stopProgressLoop();
setProgress(m_mainWindow->progressValue()/10 + 11);
//setProgress(m_mainWindow->progressValue()/10 + 11);
emit showErrorMessage("check update trigger", "no ISMAS response");
QThread::sleep(6);
}
}
setProgress(100);
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_NOT_SET_OR_WRONG,
QString("ISMAS_UPDATE-TRIGGER-NOT-SET-OR-WRONG: VALUE=(") +
triggerValue + ")");
@ -798,7 +874,7 @@ bool Worker::customerEnvironment(int progress) {
emit appendText("\nPrepare customer environment ...");
if (QDir(m_customerRepository).exists()) {
startProgressLoop();
setProgress(m_mainWindow->progressValue()/10 + 11);
// setProgress(m_mainWindow->progressValue()/10 + 11);
if (m_gc.gitCheckoutBranch()) {
stopProgressLoop();
m_ismasClient.setProgressInPercent(progress);
@ -810,7 +886,6 @@ bool Worker::customerEnvironment(int progress) {
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.checkoutBranch(m_updateStatus.m_statusDescription, ""));
setProgress(100);
emit replaceLast("Prepare customer environment ...", UPDATE_STEP_DONE);
qInfo() << "PREPARE CUSTOMER ENVIRONMENT DONE";
return true;
@ -827,12 +902,13 @@ bool Worker::customerEnvironment(int progress) {
Utils::printCriticalErrorMsg(m_customerRepository + " DOES NOT EXIST");
}
setProgress(100);
emit replaceLast("Prepare customer environment ...", UPDATE_STEP_FAIL);
return false;
}
bool Worker::filesToUpdate() {
bool Worker::filesToUpdate(int progress) {
m_ismasClient.setProgressInPercent(progress);
emit appendText("\nFetch changes files ...");
startProgressLoop();
@ -840,17 +916,11 @@ bool Worker::filesToUpdate() {
m_filesToUpdate << "etc/psa_update/opkg_commands";
if (std::optional<QString> changes = m_gc.gitPull()) {
stopProgressLoop();
int progress = (m_mainWindow->progressValue()/10) + 10;
setProgress(progress);
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES,
QString("FETCHING OF ") + m_customerRepositoryPath +
QString(" INTO ") + m_customerRepository);
setProgress(progress + 10);
if (std::optional<QStringList> changedFileNames = m_gc.gitDiff(changes.value())) {
setProgress(progress + 20);
if (m_gc.gitPull()) {
emit replaceLast(QString("Fetch changes files ..."), UPDATE_STEP_DONE);
m_filesToUpdate << changedFileNames.value();
@ -859,10 +929,6 @@ bool Worker::filesToUpdate() {
Utils::printCriticalErrorMsg("PULLING FILES FAILED");
emit replaceLast(QString("Fetch changes files ..."), UPDATE_STEP_FAIL);
stopProgressLoop();
setProgress(100);
return false;
}
}
@ -880,15 +946,13 @@ bool Worker::filesToUpdate() {
emit appendText("Found 1 file to update :", UPDATE_STEP_DONE);
emit appendText(QString("\n ") + m_filesToUpdate.at(0));
}
setProgress(progress + 30);
}
return true;
}
bool Worker::updateFiles(quint8 percent) {
QStringList filesToDownload;
bool Worker::updateFiles(int percent) {
m_filesToDownload.clear();
m_displayIndex = 0;
startProgressLoop();
for (int i = 0; i < m_filesToUpdate.size(); ++i) {
@ -941,8 +1005,6 @@ bool Worker::updateFiles(quint8 percent) {
emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(3, ' ') + QString(")")
+ QString(" Update opkg pakets ... "), UPDATE_STEP_FAIL);
stopProgressLoop();
setProgress(100);
return false;
}
}
@ -953,24 +1015,21 @@ bool Worker::updateFiles(quint8 percent) {
fName.contains("DC2C_device", Qt::CaseInsensitive) ||
fName.contains("DC2C_conf", Qt::CaseInsensitive) ||
fName.contains("DC2C_cash", Qt::CaseInsensitive)) {
filesToDownload << fName; // download printer-config-files
m_filesToDownload << fName; // download printer-config-files
} else {
static const QRegularExpression version("^.*dc2c[.][0-9]{1,2}[.][0-9]{1,2}[.]bin.*$");
if (fName.contains(version)) {
filesToDownload << fName; // download device controller
m_filesToDownload << fName; // download device controller
}
}
}
stopProgressLoop();
setProgress(100);
if (filesToDownload.size() > 0) {
Utils::printInfoMsg(QString("FILES_TO_DOWNLOAD_TO_PSA_HW ") + filesToDownload.join(','));
if (m_filesToDownload.size() > 0) {
Utils::printInfoMsg(QString("FILES_TO_DOWNLOAD_TO_PSA_HW ") + m_filesToDownload.join(','));
Update *update = m_mainWindow->getUpdate();
if (update) {
return update->doUpdate(m_displayIndex, filesToDownload);
return update->doUpdate(m_displayIndex, m_filesToDownload);
} else {
Utils::printCriticalErrorMsg("UPDATE NOT SET");
}
@ -981,9 +1040,9 @@ bool Worker::updateFiles(quint8 percent) {
return true;
}
bool Worker::syncCustomerRepositoryAndFS() {
bool Worker::syncCustomerRepositoryAndFS(int progress) {
m_ismasClient.setProgressInPercent(progress);
// this step is currently needed only for updating tariff-files
setProgress(0);
emit appendText("\nSync customer environment with filesystem ...");
if (QDir(m_customerRepository).exists()) {
if (QDir::setCurrent(m_customerRepository)) {
@ -992,8 +1051,6 @@ bool Worker::syncCustomerRepositoryAndFS() {
QStringList() << "-c" << "mkdir -p /etc/psa_config /etc/dc /etc/psa_tariff")) {
qCritical() << "COULD NOT EXECUTE '" << md.command() << "' exitCode=(" << md.exitCode() << ")";
}
int progress = 10;
setProgress(progress);
QString const params("-vvv "
"--recursive "
"--progress "
@ -1016,8 +1073,6 @@ bool Worker::syncCustomerRepositoryAndFS() {
QString cmd;
bool error = false;
foreach (cmd, cmds) {
progress += 5;
setProgress(progress);
if (!error) {
Command c("bash");
qInfo() << "EXECUTING CMD..." << cmd;
@ -1051,14 +1106,11 @@ bool Worker::syncCustomerRepositoryAndFS() {
}
}
}
progress += 5;
setProgress(progress);
if (!error) {
// now check tariff-files in etc and /etc/psa_tariff
QDir dir1(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_tariff"));
QDir dir2("/etc/psa_tariff");
if (Utils::sameFilesInDirs(dir1, dir2)) {
setProgress(100);
emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_DONE);
return true;
} else {
@ -1067,12 +1119,12 @@ bool Worker::syncCustomerRepositoryAndFS() {
}
}
}
setProgress(100);
emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_FAIL);
return false;
}
bool Worker::sendIsmasLastVersionNotification() {
bool Worker::sendIsmasLastVersionNotification(int progress) {
m_ismasClient.setProgressInPercent(progress);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_SENDVERSION#J=") +
m_ismasClient.updateOfPSASendVersion(getPSAInstalled()));
@ -1080,7 +1132,8 @@ bool Worker::sendIsmasLastVersionNotification() {
return true;
}
bool Worker::saveLogFile() {
bool Worker::saveLogFile(int progress) {
m_ismasClient.setProgressInPercent(progress);
return true;
}
QString Worker::getOsVersion() const {
@ -1320,6 +1373,7 @@ hwinf const *Worker::getPlugin() const {
/************************************************************************************************
* operators
*/
#if 0
QDebug operator<< (QDebug debug, UpdateStatus status) {
switch(status.m_updateStatus) {
case UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED:
@ -1573,3 +1627,4 @@ QString& operator<< (QString& str, UpdateStatus status) {
}
return str;
}
#endif

282
worker.h
View File

@ -8,13 +8,17 @@
#include <QFile>
#include <QJsonObject>
#include <QHash>
#include <QMap>
#include <QDebug>
#include <optional>
#include <initializer_list>
#include "worker_thread.h"
#include "update.h"
#include "git/git_client.h"
#include "ismas/ismas_client.h"
#include "utils.h"
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
@ -65,8 +69,6 @@ struct UpdateStatus {
: m_updateStatus(s), m_statusDescription(d) {}
};
QDebug operator<<(QDebug debug, UpdateStatus status);
QString& operator<<(QString &str, UpdateStatus status);
#define ISMAS_UPDATE_REQUESTS (10)
@ -109,12 +111,12 @@ class Worker : public QObject {
UpdateStatus m_updateStatus;
QStringList m_filesToUpdate;
QStringList m_filesToDownload;
bool m_updateProcessRunning;
int m_displayIndex;
int m_returnCode;
MainWindow *m_mainWindow;
int m_progressValue;
bool m_withoutIsmasDirectPort;
QString m_apismVersion;
@ -135,10 +137,70 @@ class Worker : public QObject {
int sendCloneAndCheckoutSuccess();
int sendCloneAndCheckoutFailure();
int sendIsmasTriggerFailure();
int sendPullFailure();
int sendFileUpdateFailure();
int sendRsyncFailure();
int sendLastVersionFailure();
int sendSaveLogFilesFailure();
int sendCustomerEnvironmentConfigurationFailed();
int sendFoundFilesToUpdateSuccess();
int sendUpdateSucceededAndActivated();
int sendFinalResult();
static constexpr const int UPDATE_SUCCESS_AND_ACTIVATED = 0;
static constexpr const int CLONE_AND_CHECKOUT_SUCCESS = 0;
static constexpr const int CLONE_AND_CHECKOUT_FAILURE = -3;
static constexpr const int ISMAS_TRIGGER_FAILURE = -5;
static constexpr const int ENVIRONMENT_CONFIG_FAILURE = -6;
static constexpr const int GIT_PULL_FAILURE = -7;
static constexpr const int UPDATE_FILES_FAILURE = -8;
static constexpr const int RSYNC_FAILURE = -9;
static constexpr const int SEND_LAST_VERSION_FAILURE = -10;
static constexpr const int SAVE_LOG_FILES_FAILURE = -11;
enum class UPDATE_STEP {
STARTED = 1,
CHECK_REPOSITORY = 2,
CHECK_SANITY = 3,
CHECK_SANITY_SUCCESS = 4,
CHECK_SANITY_FAILURE = 5,
CLONE_REPOSITORY = 6,
CLONE_REPOSITORY_SUCCESS = 7,
CLONE_REPOSITORY_FAILURE = 8,
SWITCH_BRANCH = 12,
SWITCH_BRANCH_SUCCESS = 13,
SWITCH_BRANCH_FAILURE = 14,
CHECK_ISMAS_TRIGGER = 15,
CHECK_ISMAS_TRIGGER_SUCCESS = 23,
CHECK_ISMAS_TRIGGER_FAILURE = 24,
UPDATE_REPOSITORY = 25,
UPDATE_REPOSITORY_SUCCESS = 28,
UPDATE_REPOSITORY_FAILURE = 29,
CHECK_FOR_REPOSITORY_CHANGES = 30,
CHECK_FOR_REPOSITORY_CHANGES_SUCCESS = 38,
CHECK_FOR_REPOSITORY_CHANGES_FAILURE = 39,
APPLY_REPOSITORY_CHANGES = 40,
DOWNLOAD_CONFIG_FILE = 41,
DOWNLOAD_CONFIG_FILE_SUCCESS = 63,
DOWNLOAD_CONFIG_FILE_FAILURE = 64,
DOWNLOAD_DEVICE_CONTROLLER = 65,
DOWNLOAD_DEVICE_CONTROLLER_SUCCESS = 86,
DOWNLOAD_DEVICE_CONTROLLER_FAILURE = 87,
APPLY_REPOSITORY_CHANGES_SUCCESS = 88,
APPLY_REPOSITORY_CHANGES_FAILURE = 89,
SYNC_CUSTOMER_REPOSITORY = 90,
SYNC_CUSTOMER_REPOSITORY_SUCCESS = 91,
SYNC_CUSTOMER_REPOSITORY_FAILURE = 92,
SAVE_LOGS = 94,
SAVE_LOGS_SUCCESS = 95,
SAVE_LOGS_FAILURE = 96,
SEND_LAST_VERSION = 97,
UPDATE_SUCCEEDED = 98,
UPDATE_FAILED = 99,
FINISHED = 100
};
static Worker const *instance;
public:
static QString getATBUpdateToolYoctoVersion();
@ -165,6 +227,7 @@ public:
hwinf *getPlugin();
hwinf const *getPlugin() const;
void setProgress(int progress);
void displayProgressInMainWindow(int progress);
void startProgressLoop();
void stopProgressLoop();
@ -183,15 +246,6 @@ public:
MainWindow *mainWindow() { return m_mainWindow; }
MainWindow const *mainWindow() const { return m_mainWindow; }
//friend QDebug operator<<(QDebug debug, Worker const &w) {
// Q_UNUSED(w);
// return debug;
//}
//friend QString& operator<<(QString &str, Worker const &w) {
// Q_UNUSED(w);
// return str;
//}
signals:
void appendText(QString, QString suffix = "");
void replaceLast(QString, QString);
@ -209,16 +263,210 @@ public slots:
private slots:
bool updateTriggerSet(int progress);
bool customerEnvironment(int progress);
bool filesToUpdate();
bool updateFiles(quint8 percent);
bool syncCustomerRepositoryAndFS();
bool sendIsmasLastVersionNotification();
bool saveLogFile();
bool filesToUpdate(int progress);
bool updateFiles(int percent);
bool syncCustomerRepositoryAndFS(int progress);
bool sendIsmasLastVersionNotification(int progress);
bool saveLogFile(int progress);
private:
PSAInstalled getPSAInstalled();
void privateUpdate();
std::optional<QString> getApismVersion();
void printProgress(UPDATE_STEP step);
friend QDebug operator<<(QDebug debug, UPDATE_STEP step) {
if (!Worker::instance) {
return debug;
}
static const QMap<UPDATE_STEP, const char*> smap (
std::initializer_list<std::pair<UPDATE_STEP, const char*>>{
#define INSERT_ELEMENT(p) std::pair(p, #p)
INSERT_ELEMENT(UPDATE_STEP::STARTED),
INSERT_ELEMENT(UPDATE_STEP::CHECK_REPOSITORY),
INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY),
INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY),
INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::SWITCH_BRANCH),
INSERT_ELEMENT(UPDATE_STEP::SWITCH_BRANCH_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::SWITCH_BRANCH_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER),
INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY),
INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES),
INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::APPLY_REPOSITORY_CHANGES),
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE),
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER),
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::APPLY_REPOSITORY_CHANGES_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::APPLY_REPOSITORY_CHANGES_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY),
INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS),
INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS_SUCCESS),
INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS_FAILURE),
INSERT_ELEMENT(UPDATE_STEP::SEND_LAST_VERSION),
INSERT_ELEMENT(UPDATE_STEP::UPDATE_SUCCEEDED),
INSERT_ELEMENT(UPDATE_STEP::UPDATE_FAILED),
INSERT_ELEMENT(UPDATE_STEP::FINISHED)
#undef INSERT_ELEMENT
});
switch (step) {
case UPDATE_STEP::STARTED:
break;
case UPDATE_STEP::CHECK_REPOSITORY:
break;
case UPDATE_STEP::CHECK_SANITY:
break;
case UPDATE_STEP::CHECK_SANITY_SUCCESS:
break;
case UPDATE_STEP::CHECK_SANITY_FAILURE:
break;
case UPDATE_STEP::CLONE_REPOSITORY:
break;
case UPDATE_STEP::CLONE_REPOSITORY_SUCCESS:
break;
case UPDATE_STEP::CLONE_REPOSITORY_FAILURE:
break;
case UPDATE_STEP::SWITCH_BRANCH:
break;
case UPDATE_STEP::SWITCH_BRANCH_SUCCESS:
break;
case UPDATE_STEP::SWITCH_BRANCH_FAILURE:
break;
case UPDATE_STEP::CHECK_ISMAS_TRIGGER:
break;
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS:
break;
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE:
break;
case UPDATE_STEP::UPDATE_REPOSITORY:
break;
case UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS:
break;
case UPDATE_STEP::UPDATE_REPOSITORY_FAILURE:
break;
case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES:
break;
case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_SUCCESS:
break;
case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_FAILURE:
break;
case UPDATE_STEP::APPLY_REPOSITORY_CHANGES:
break;
case UPDATE_STEP::DOWNLOAD_CONFIG_FILE:
break;
case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_SUCCESS:
break;
case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_FAILURE:
break;
case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER:
break;
case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS:
break;
case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE:
break;
case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_SUCCESS:
break;
case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_FAILURE:
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY:
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS:
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE:
break;
case UPDATE_STEP::SAVE_LOGS:
break;
case UPDATE_STEP::SAVE_LOGS_SUCCESS:
break;
case UPDATE_STEP::SAVE_LOGS_FAILURE:
break;
case UPDATE_STEP::SEND_LAST_VERSION:
break;
case UPDATE_STEP::UPDATE_SUCCEEDED:
break;
case UPDATE_STEP::UPDATE_FAILED:
break;
case UPDATE_STEP::FINISHED:
break;
}
#if 0
case UPDATE_STEP::CHECK_SANITY:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 1: CHECKED SANITY OF CUSTOMER REPOSITORY %1 DONE")
.arg(instance->m_customerRepository)
<< QString("STEP 2: FETCH CUSTOMER REPOSITORY %1...")
.arg(instance->m_customerRepository));
break;
//case UPDATE_STEP::FETCH_REPOSITORY:
// Utils::printUpdateStatusMsg(
// QStringList()
// << QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
// .arg(instance->m_customerRepository)
// << QString("STEP 3: CHECK ISMAS-UPDATE-TRIGGER FOR WAIT-STATUS..."));
// break;
case UPDATE_STEP::CHECK_ISMAS_TRIGGER:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 3: CHECKED ISMAS-UPDATE-TRIGGER FOR WAIT-STATUS. SUCCESS.")
<< QString("STEP 4: CHECK-OUT BRANCH %1...").arg(instance->m_gc.branchName()));
break;
case UPDATE_STEP::CHECKED_OUT_BRANCH:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 4: CHECKED-OUT BRANCH %1 DONE")
.arg(instance->m_gc.branchName())
<< QString("STEP 5: COMPUTE FILES-TO-UPDATE..."));
break;
case UPDATE_STEP::COMPUTE_FILES_TO_UPDATE:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 5: COMPUTE FILES-TO-UPDATE %1 DONE")
.arg(instance->m_filesToUpdate.join(','))
<< QString("STEP 6: DOWNLOAD FILES-TO-DOWNLOAD %1 AND EXECUTE OPKG_COMMANDS...")
.arg(instance->m_filesToDownload.join(',')));
break;
case UPDATE_STEP::DOWNLOAD_FILES_TO_UPDATE:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 6: DOWNLOAD FILES-TO-DOWNLOAD %1 AND EXECUTE OPKG_COMMANDS DONE")
.arg(instance->m_filesToDownload.join(','))
<< QString("STEP 7: SYNC CUSTOMER REPOSITORY %1 WITH FILESYSTEM...")
.arg(instance->m_customerRepository));
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 7: SYNC CUSTOMER REPOSITORY %1 WITH FILESYSTEM DONE")
.arg(instance->m_customerRepository)
<< QString("STEP 8: SEND-LAST-VERSION TO ISMAS..."));
break;
case UPDATE_STEP::UPDATE_SUCCESS:
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 9: SAVE-LOG-FILES (FUTURE USE) DONE")
<< QString("STEP 10: MARK UPDATE AS SUCCESSFUL AND ACTIVE..."));
break;
}
#endif
return debug;
}
};
#endif // WORKER_H_INCLUDED