Commit 7a7d24d7 by Belákovics Ádám

masodik iteracio

parent a4adc867
......@@ -8,6 +8,7 @@ struct ComputeData{
int cores;
std::string hostname;
int port;
std::string username;
std::string password;
};
......
......@@ -28,22 +28,27 @@ void ComputeWidget::on_bRenew_clicked()
emit renew(id);
}
void ComputeWidget::on_bWakeUp_clicked()
{
emit wakeup(id);
}
void ComputeWidget::on_bSleep_clicked()
{
emit sleep(id);
}
void ComputeWidget::on_pushButton_clicked()
void ComputeWidget::on_bStart_clicked()
{
//TODO
emit start(id);
}
void ComputeWidget::on_bStart_clicked()
void ComputeWidget::on_bWakeUpSleep_clicked()
{
emit start(id);
emit wakeupsleep(id);
}
void ComputeWidget::stateChangedHandler(std::string newState, std::string _id){
if(id == _id){ //check if we changed or not
if(newState == "suspended" || newState == "inactive"){
ui->bWakeUpSleep->setText("Wake up");
ui->bWakeUpSleep->setStyleSheet("background-color:green");
}
else if(newState == "active"){
ui->bWakeUpSleep->setText("Sleep");
ui->bWakeUpSleep->setStyleSheet("background-color:yellow");
}
else
throw std::runtime_error("undefined VM state!");
}
}
......@@ -22,20 +22,19 @@ public:
signals:
void start(std::string id);
void sleep(std::string id);
void wakeup(std::string id);
void wakeupsleep(std::string id);
void renew(std::string id);
public slots:
void stateChangedHandler(std::string newState, std::string id);
private slots:
void on_bRenew_clicked();
void on_bWakeUp_clicked();
void on_bSleep_clicked();
void on_bStart_clicked();
void on_pushButton_clicked();
void on_bWakeUpSleep_clicked();
void on_bStart_clicked();
private:
Ui::ComputeWidget *ui;
......
......@@ -22,21 +22,21 @@
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="7" column="3" rowspan="2">
<item row="6" column="2" rowspan="2">
<widget class="QPushButton" name="bRenew">
<property name="text">
<string>Renew</string>
</property>
</widget>
</item>
<item row="5" column="3" rowspan="2">
<widget class="QPushButton" name="bWakeUp">
<item row="4" column="2" rowspan="2">
<widget class="QPushButton" name="bWakeUpSleep">
<property name="text">
<string>Wake up</string>
</property>
</widget>
</item>
<item row="7" column="0" rowspan="2">
<item row="6" column="0" rowspan="2">
<widget class="QLabel" name="lHostName">
<property name="text">
<string>Virtual Machine</string>
......@@ -46,7 +46,7 @@
</property>
</widget>
</item>
<item row="2" column="0" rowspan="5">
<item row="2" column="0" rowspan="4">
<widget class="QLabel" name="lComputeIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
......@@ -67,7 +67,7 @@
</property>
</widget>
</item>
<item row="2" column="1" rowspan="7">
<item row="2" column="1" rowspan="6">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -80,14 +80,7 @@
</property>
</spacer>
</item>
<item row="5" column="2" rowspan="2">
<widget class="QPushButton" name="bSleep">
<property name="text">
<string>Sleep</string>
</property>
</widget>
</item>
<item row="2" column="3" rowspan="3">
<item row="2" column="2" rowspan="2">
<widget class="QPushButton" name="bStart">
<property name="text">
<string>Start</string>
......
#include "controller.h"
bool Controller::connect(){
session = new OcciClient::OcciSession("https://vm.ik.bme.hu:9366/occi/", true, true);
bool Controller::connect(std::string url){
session = new OcciClient::OcciSession(url.c_str(), true, true);
return true; //TODO validation
}
......@@ -14,11 +14,16 @@ bool Controller::login(std::string username, std::string password){
return false;
}
/*!
* \brief Refreshes all data, communicates with the server
*/
void Controller::refresh(){
allCompute.clear();
for(auto c : OcciClient::Compute::getComputeInstances(session)){
for(auto c : OcciClient::Compute::getComputeInstances(session))
allCompute.push_back(c);
}
allTemplate.clear();
for (auto t : OcciClient::getTemplates(session))
allTemplate.push_back(t);
}
std::vector<std::string> Controller::getVMs(){
......@@ -29,20 +34,32 @@ std::vector<std::string> Controller::getVMs(){
return VMs;
}
std::vector<std::string> Controller::getTemplates(){
std::vector<std::string> templates;
for(auto t : allTemplate){
templates.push_back(t);
}
return templates;
}
void Controller::renewByID(std::string id){
allCompute.at(std::stoi(id))->renew();
refresh();
}
void Controller::startByID(std::string id){
allCompute.at(std::stoi(id))->start();
refresh();
}
void Controller::wakeupByID(std::string id){
allCompute.at(std::stoi(id))->wakeup();
refresh();
}
void Controller::sleepByID(std::string id){
allCompute.at(std::stoi(id))->sleep();
refresh();
}
std::string Controller::getState(std::string id){
......@@ -55,6 +72,7 @@ ComputeData Controller::getDataByID(std::string id){
data.cpu = allCompute.at(std::stoi(id))->getCpuShare();
data.cores = allCompute.at(std::stoi(id))->getCores();
data.hostname = allCompute.at(std::stoi(id))->getCredentialHost();
data.port = allCompute.at(std::stoi(id))->getCredentialPort();
data.username = allCompute.at(std::stoi(id))->getCredentialUsername();
data.password = allCompute.at(std::stoi(id))->getCredentialPassword();
return data;
......@@ -62,4 +80,5 @@ ComputeData Controller::getDataByID(std::string id){
void Controller::newCompute(Template t){
OcciClient::Compute::createComputeInstance(session, t);
refresh();
}
......@@ -12,8 +12,9 @@ class Controller
public:
OcciClient::OcciSession* session;
std::vector<std::shared_ptr<OcciClient::Compute> > allCompute;
std::vector<Template> allTemplate;
bool connect();
bool connect(std::string url);
bool login(std::string username, std::string password);
......@@ -34,6 +35,8 @@ public:
std::string getState(std::string id);
std::vector<std::string> getVMs();
std::vector<std::string> getTemplates();
};
#endif // CONTROLLER_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
///Implementation for class MainWindow
///
///---------------------------------------------------------------------------------------------------
/// Basic Methods
/*!
* \brief Constructor, sets up ui, disable tabs other than login
* \param parent
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
......@@ -8,39 +17,80 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
ui->tabWidget->setTabEnabled(1, false);
ui->tabWidget->setTabEnabled(2, false);
myController.connect();
}
/*!
* \brief Destructor
*/
MainWindow::~MainWindow()
{
delete ui;
}
///---------------------------------------------------------------------------------------------------
/// Methods for loading data to the UI
/*!
* \brief Adds a VM to the listWidget, sets its id, connects all Quick Action buttons
* \param id
* \param name
*/
void MainWindow::addVM(std::string id, std::string name){
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
ComputeWidget* cw = new ComputeWidget();
cw->setID(id);
cw->setName(name);
connect(this, SIGNAL(stateChanged(std::string, std::string)), cw, SLOT(stateChangedHandler(std::string, std::string)));
emit stateChanged(myController.getState(id), id);
connect(cw, SIGNAL(renew(std::string)), this, SLOT(renewClicked(std::string)));
connect(cw, SIGNAL(start(std::string)), this, SLOT(startClicked(std::string)));
connect(cw, SIGNAL(wakeup(std::string)), this, SLOT(wakeupClicked(std::string)));
connect(cw, SIGNAL(sleep(std::string)), this, SLOT(sleepClicked(std::string)));
connect(cw, SIGNAL(wakeupsleep(std::string)), this, SLOT(wakeupsleepClicked(std::string)));
item->setSizeHint(cw->minimumSize());
ui->listWidget->addItem(item);
ui->listWidget->setItemWidget(item, cw);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadData(){
/*!
* \brief loads all data to the UI, which are stored in Controller, DOES NOT COMMUNICATE WITH THE CLOUD SERVER!!
*/
void MainWindow::loadAllData(){
VM_names = myController.getVMs();
ui->listWidget->clear();
for(size_t i = 0; i < VM_names.size(); i++)
addVM(std::to_string(i), VM_names.at(i));
for(auto t : getTemplates(myController.session))
ui->lwTemplates->clear();
for(auto t : myController.getTemplates())
ui->lwTemplates->addItem(t.c_str());
}
/*!
* \brief Loads all data for a VM specified by the id, does NOT communicate with the cloud server!!
* \param id
*/
void MainWindow::loadVMData(std::string id){
ui->lStatus->setText(myController.getState(id).c_str());
ComputeData data = myController.getDataByID(id.c_str());
ui->lCPU->setText(std::to_string(data.cpu).c_str());
ui->lMemory->setText(std::to_string(data.memory).c_str());
ui->lCores->setText(std::to_string(data.cores).c_str());
ui->lHostname->setText((data.hostname + ":" + std::to_string(data.port)).c_str());
ui->lUsernameVM->setText(data.username.c_str());
ui->lPasswordVM->setText(data.password.c_str());
}
///---------------------------------------------------------------------------------------------------
/// Button handlers
///Tab 0 - Login Screen
/*!
* \brief Login Button handler, connects to server, if authentication is succesful enables all tabs, and loads all data
*/
void MainWindow::on_bLogin_clicked()
{
std::string serverUrl = ui->iCloudServer->text().toStdString();
myController.connect(serverUrl);
std::string username = ui->iUsername->text().toStdString();
std::string password = ui->iPassword->text().toStdString();
if(!myController.login(username, password)){
......@@ -49,47 +99,72 @@ void MainWindow::on_bLogin_clicked()
}
ui->tabWidget->setTabEnabled(1, true);
ui->tabWidget->setTabEnabled(2, true);
loadData();
loadAllData();
ui->tabWidget->setCurrentIndex(1);
}
/// Tab 1 - Virtual Machines
/*!
* \brief handles Renew button, all static data is refreshed
* \param id
*/
void MainWindow::renewClicked(std::string id){
myController.renewByID(id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
/*!
* \brief handles Start button (fetches data from server)
* \param id
*/
void MainWindow::startClicked(std::string id){
myController.startByID(id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
void MainWindow::wakeupClicked(std::string id){
myController.wakeupByID(id);
}
void MainWindow::sleepClicked(std::string id){
myController.sleepByID(id);
void MainWindow::wakeupsleepClicked(std::string id){
std::string state = myController.getState(id);
if(state == "active"){ //sleep
myController.sleepByID(id);
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
else if(state == "suspended" || state == "inactive"){ //wake up
myController.wakeupByID(id);
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
else{
throw std::runtime_error("undefined VM STATE!!!");
}
}
/*!
* \brief handles Renew button (fetches data from server)
* \param id
*/
void MainWindow::on_listWidget_clicked(const QModelIndex &index)
{
ui->lStatus->setText(myController.getState(std::to_string(index.row())).c_str());
ComputeData data = myController.getDataByID(std::to_string(index.row()).c_str());
ui->lCPU->setText(std::to_string(data.cpu).c_str());
ui->lMemory->setText(std::to_string(data.memory).c_str());
ui->lCores->setText(std::to_string(data.cores).c_str());
ui->lHostname->setText((data.hostname+":21231").c_str()); //TODO
ui->lUsername->setText(data.username.c_str());
ui->lPassword->setText(data.password.c_str());
loadVMData(std::to_string(index.row()));
}
/*!
* \brief handles Refresh button, refreshes Controller's data and loads to the UI (fetches data from server)
*/
void MainWindow::on_bRefresh_clicked()
{
myController.refresh();
loadData();
}
void MainWindow::receive_chosen_template(Template t){
myController.newCompute(t);
loadAllData();
}
/*!
* \brief handles new VM button, Opens a dialog for choosing from templates
*/
void MainWindow::on_bNewVM_clicked()
{
VMChooserDialog* v = new VMChooserDialog(this);
......@@ -97,3 +172,29 @@ void MainWindow::on_bNewVM_clicked()
connect(v, SIGNAL(send_chosen_template(Template)), this, SLOT(receive_chosen_template(Template)));
v->exec();
}
/*!
* \brief Slot for dialog, creates new VM by the chosen template
* \param t
*/
void MainWindow::receive_chosen_template(Template t){
myController.newCompute(t);
loadAllData();
}
/*!
* \brief handler, shows/hides VM password
*/
void MainWindow::on_bShowPassword_clicked()
{
if(ui->lPasswordVM->echoMode() == QLineEdit::Password){
ui->lPasswordVM->setEchoMode(QLineEdit::Normal);
ui->bShowPassword->setText("Hide");
}
else if(ui->lPasswordVM->echoMode() == QLineEdit::Normal){
ui->lPasswordVM->setEchoMode(QLineEdit::Password);
ui->bShowPassword->setText("Show");
}
else
ui->lPasswordVM->setEchoMode(QLineEdit::Password);
}
......@@ -4,6 +4,7 @@
#include <QMainWindow>
#include <QLabel>
#include <QPushButton>
#include <QListWidget>
#include <computewidget.h>
#include "libocci/occilib.h"
#include "controller.h"
......@@ -21,17 +22,18 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void addVM(std::string id, std::string name);
void loadData();
void loadAllData();
void loadVMData(std::string id);
signals:
void send_templates(std::vector<Template>);
void stateChanged(std::string state, std::string id);
private slots:
void on_bLogin_clicked();
void renewClicked(std::string);
void startClicked(std::string);
void wakeupClicked(std::string);
void sleepClicked(std::string);
void wakeupsleepClicked(std::string);
void receive_chosen_template(Template);
......@@ -41,6 +43,8 @@ private slots:
void on_bNewVM_clicked();
void on_bShowPassword_clicked();
private:
Ui::MainWindow *ui;
Controller myController;
......
......@@ -48,7 +48,7 @@
</palette>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>CircleClient</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
......@@ -95,7 +95,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<property name="iconSize">
<size>
......@@ -108,14 +108,20 @@
<string>Welcome</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="8" column="1">
<item row="10" column="1">
<widget class="QPushButton" name="bLogin">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Log in&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="9" column="1">
<widget class="QLineEdit" name="iPassword">
<property name="palette">
<palette>
......@@ -165,7 +171,7 @@
</property>
</widget>
</item>
<item row="3" column="2" rowspan="8">
<item row="3" column="2" rowspan="10">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -181,7 +187,7 @@
</property>
</spacer>
</item>
<item row="3" column="0" rowspan="8">
<item row="3" column="0" rowspan="10">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -197,7 +203,7 @@
</property>
</spacer>
</item>
<item row="10" column="1">
<item row="12" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -213,14 +219,14 @@
</property>
</spacer>
</item>
<item row="6" column="1">
<item row="8" column="1">
<widget class="QLabel" name="lPassword">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="7" column="1">
<widget class="QLineEdit" name="iUsername">
<property name="palette">
<palette>
......@@ -277,7 +283,7 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<item row="6" column="1">
<widget class="QLabel" name="lUsername">
<property name="text">
<string>Username</string>
......@@ -307,7 +313,7 @@
</property>
</widget>
</item>
<item row="9" column="1">
<item row="11" column="1">
<widget class="QLabel" name="lInfo">
<property name="palette">
<palette>
......@@ -354,6 +360,57 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="lCloudServer">
<property name="text">
<string>Cloud Server:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="iCloudServer">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>240</red>
<green>240</green>
<blue>240</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string>https://vm.ik.bme.hu:9366/occi/</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tVM">
......@@ -417,6 +474,13 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lMemoryTag">
<property name="text">
<string>Memory:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
......@@ -514,10 +578,17 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lMemoryTag">
<item row="7" column="2">
<widget class="QLabel" name="lHostname">
<property name="text">
<string>Memory:</string>
<string/>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QLabel" name="lUsernameVM">
<property name="text">
<string/>
</property>
</widget>
</item>
......@@ -554,29 +625,75 @@
</property>
</spacer>
</item>
<item row="7" column="2">
<widget class="QLabel" name="lHostname">
<property name="text">
<string/>
<item row="9" column="2">
<widget class="QLineEdit" name="lPasswordVM">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>240</red>
<green>240</green>
<blue>240</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QLabel" name="lUsernameVM">
<property name="text">
<string/>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="QLabel" name="lPasswordVM">
<item row="9" column="3">
<widget class="QPushButton" name="bShowPassword">
<property name="text">
<string/>
<string>Show</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tTemplate">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment