Commit abd4b94a authored by Stan Hammon's avatar Stan Hammon Committed by John Tourtellott
Browse files

Added a widget to view active AWS clusters

parent f302f047
......@@ -11,7 +11,12 @@
#include "smtk/newt/qtNewtInterface.h"
#include "smtk/simulation/ace3p/qt/qtCloudClusterWidget.h"
#include "pqCoreUtilities.h"
#include <QDebug>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
......@@ -63,13 +68,18 @@ void pqACE3PCloudAWSBehavior::listClusters()
QString url = QString("https://f001.backblazeb2.com/file/kitware/ace3p/shared/clusters.json");
QNetworkRequest request(url);
QNetworkReply* reply = networkManager->get(request);
// Stan todo: check for error
QObject::connect(reply, &QNetworkReply::finished, [this, reply]() {
// Stan todo check for error
// Stan todo display qtCloudClusterWidget
// columns: Name, Status, Instance Type, Max Instances, Region
QObject::connect(reply, &QNetworkReply::finished, [reply]() {
if (reply->error() != QNetworkReply::NoError)
{
QMessageBox::critical(pqCoreUtilities::mainWidget(), "Network Error", reply->errorString());
reply->deleteLater();
return;
}
QString text = reply->readAll().constData();
qDebug() << text;
qtCloudClusterWidget * clusterWidget = new qtCloudClusterWidget(pqCoreUtilities::mainWidget());
clusterWidget->setData(text);
clusterWidget->show();
reply->deleteLater();
});
......
set(ui_files
qtCloudClusterWidget.ui
qtJobsWidget.ui
qtModeSelectDialog.ui
qtNewProjectMeshPage.ui
......@@ -12,6 +13,7 @@ qt5_add_resources (RCC_SOURCES icons/jobWidgetIcons.qrc)
set(qt_sources
${RCC_SOURCES}
qtAbstractJobTracker.cxx
qtCloudClusterWidget.cxx
# qtCumulusJobTracker.cxx
qtJobsModel.cxx
qtJobsWidget.cxx
......@@ -34,6 +36,7 @@ set(qt_sources
set(qt_headers
qtAbstractJobTracker.h
qtCloudClusterWidget.h
# qtCumulusJobTracker.h
qtJobsModel.h
qtJobsWidget.h
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "qtCloudClusterWidget.h"
#include "ui_qtCloudClusterWidget.h"
//#include <QApplication>
//#include <QCoreApplication>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
// constructor
qtCloudClusterWidget::qtCloudClusterWidget(QWidget* parent)
: QDialog(parent)
, ui(new Ui::qtCloudClusterWidget)
{
this->ui->setupUi(this);
this->setWindowTitle("AWS Clusters");
this->setMinimumSize(500, 260);
// hide the question mark in the Window Title Bar
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
this->ui->tableWidget->setColumnCount(5);
QStringList headers = { "Name", "Status", "Instance Type", "Max Instances", "Region" };
this->ui->tableWidget->setHorizontalHeaderLabels(headers);
this->ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
this->ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
this->ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
// destructor
qtCloudClusterWidget::~qtCloudClusterWidget()
{
delete ui;
}
void qtCloudClusterWidget::on_pushButton_Close_clicked()
{
this->close();
this->deleteLater();
}
void qtCloudClusterWidget::setData(const QString &jsonData)
{
// get JSON array
QJsonObject data = QJsonDocument::fromJson(jsonData.toUtf8()).object();
QJsonArray array = data["clusters"].toArray();
// add array items to tabelWidget
this->ui->tableWidget->setRowCount(array.count());
for (int i=0; i<array.count(); i++ )
{
QJsonObject entry = array[i].toObject();
QTableWidgetItem * item = new QTableWidgetItem(entry.value("name").toString());
this->ui->tableWidget->setItem(i, 0, item);
item = new QTableWidgetItem(entry.value("status").toString());
this->ui->tableWidget->setItem(i, 1, item);
item = new QTableWidgetItem(entry.value("instance_type").toString());
this->ui->tableWidget->setItem(i, 2, item);
item = new QTableWidgetItem(QString("%1").arg(entry.value("max_instances").toInt()));
this->ui->tableWidget->setItem(i, 3, item);
item = new QTableWidgetItem(entry.value("region").toString());
this->ui->tableWidget->setItem(i, 4, item);
}
}
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef smtk_simulation_ace3p_qt_qtCloudClusterWidget
#define smtk_simulation_ace3p_qt_qtCloudClusterWidget
#include <QDialog>
#include <QMutex>
#include <QPixmap>
#include <QTime>
#include <QTimer>
#include "smtk/simulation/ace3p/qt/Exports.h"
namespace Ui
{
class qtCloudClusterWidget;
}
/**
* \brief Displays the AWS Clusters that are available.
*/
class SMTKACE3PQTEXT_EXPORT qtCloudClusterWidget : public QDialog
{
Q_OBJECT
public:
explicit qtCloudClusterWidget(QWidget* parent = nullptr);
~qtCloudClusterWidget();
/** @brief Sets the JSON data to be displayed in the table widget. */
void setData(const QString &jsonData);
private slots:
void on_pushButton_Close_clicked();
private:
Ui::qtCloudClusterWidget* ui;
};
#endif // smtk_simulation_ace3p_qt_qtCloudClusterWidget
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>qtCloudClusterWidget</class>
<widget class="QWidget" name="qtCloudClusterWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="tableWidget"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>278</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_Close">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment