/*
* Copyright (c) 2010-2012 Thiago T. Sá
*
* This file is part of CloudReports.
*
* CloudReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CloudReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For more information about your rights as a user of CloudReports,
* refer to the LICENSE file or see <http://www.gnu.org/licenses/>.
*/
package cloudreports.gui.customers;
import cloudreports.dao.CustomerRegistryDAO;
import cloudreports.dao.VirtualMachineRegistryDAO;
import cloudreports.enums.CloudletScheduler;
import cloudreports.gui.MainView;
import cloudreports.models.CustomerRegistry;
import cloudreports.models.VirtualMachineRegistry;
/**
* The EditVm form.
* Most of its code is generated automatically by the NetBeans IDE.
*
* @author Thiago T. Sá
* @since 1.0
*/
public class EditVm extends javax.swing.JDialog {
/** The virtual machine being edited. */
private VirtualMachineRegistry vmr;
/** An instance of virtual machine registry DAO. */
VirtualMachineRegistryDAO vrDAO;
/** A specific customer view. */
SpecificCustomerView scv;
/**
* Gets the virtual machine registry being edited.
*
* @return the virtual machine registry being edited.
*/
public VirtualMachineRegistry getVmr() {
return this.vmr;
}
/** Creates a new EditVm form. */
public EditVm(VirtualMachineRegistry vmr, SpecificCustomerView scv) {
this.vmr=vmr;
this.vrDAO = new VirtualMachineRegistryDAO();
this.scv=scv;
initComponents();
amountSpinner.setValue(vmr.getAmount());
imageSizeSpinner.setValue(vmr.getSize());
pesSpinner.setValue(vmr.getPesNumber());
mipsSpinner.setValue(vmr.getMips());
ramSpinner.setValue(vmr.getRam());
bwSpinner.setValue(vmr.getBw());
prioritySpinner.setValue(vmr.getPriority());
if(vmr.getVmm().equalsIgnoreCase("Xen")) hypervisorComboBox.setSelectedIndex(0);
else hypervisorComboBox.setSelectedIndex(1);
policyComboBox.setSelectedItem(vmr.getSchedulingPolicyAlias());
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSpinner6 = new javax.swing.JSpinner();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
pesSpinner = new javax.swing.JSpinner();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
imageSizeSpinner = new javax.swing.JSpinner();
amountSpinner = new javax.swing.JSpinner();
mipsSpinner = new javax.swing.JSpinner();
ramSpinner = new javax.swing.JSpinner();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
policyComboBox = new javax.swing.JComboBox();
hypervisorComboBox = new javax.swing.JComboBox();
prioritySpinner = new javax.swing.JSpinner();
bwSpinner = new javax.swing.JSpinner();
okButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Edit Virtual Machine");
setModal(true);
setResizable(false);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings"));
jLabel1.setText("Amount:");
pesSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1)));
pesSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
pesSpinnerStateChanged(evt);
}
});
jLabel2.setText("Image size:");
jLabel3.setText("Proc. Elements:");
jLabel4.setText("MIPS:");
jLabel5.setText("RAM:");
imageSizeSpinner.setModel(new javax.swing.SpinnerNumberModel(Long.valueOf(1L), Long.valueOf(1L), null, Long.valueOf(100L)));
imageSizeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
imageSizeSpinnerStateChanged(evt);
}
});
amountSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1)));
amountSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
amountSpinnerStateChanged(evt);
}
});
mipsSpinner.setModel(new javax.swing.SpinnerNumberModel(Long.valueOf(1L), Long.valueOf(1L), null, Long.valueOf(50L)));
mipsSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
mipsSpinnerStateChanged(evt);
}
});
ramSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(64)));
ramSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
ramSpinnerStateChanged(evt);
}
});
jLabel6.setText("Bandwidth:");
jLabel7.setText("Priority:");
jLabel8.setText("Hypervisor:");
jLabel9.setText("Scheduling policy:");
policyComboBox.setModel(new javax.swing.DefaultComboBoxModel(CloudletScheduler.getCloudletSchedulersNames()));
policyComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
policyComboBoxItemStateChanged(evt);
}
});
hypervisorComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Xen", "KVM" }));
hypervisorComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
hypervisorComboBoxItemStateChanged(evt);
}
});
prioritySpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
prioritySpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
prioritySpinnerStateChanged(evt);
}
});
bwSpinner.setModel(new javax.swing.SpinnerNumberModel(Long.valueOf(0L), Long.valueOf(0L), null, Long.valueOf(100L)));
bwSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
bwSpinnerStateChanged(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(ramSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(imageSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(pesSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(mipsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(amountSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(bwSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(prioritySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(policyComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(hypervisorComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {amountSpinner, bwSpinner, imageSizeSpinner, mipsSpinner, pesSpinner, prioritySpinner, ramSpinner});
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {hypervisorComboBox, policyComboBox});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel1)
.addComponent(amountSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(bwSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel2)
.addComponent(imageSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(prioritySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel3)
.addComponent(pesSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8)
.addComponent(hypervisorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel4)
.addComponent(mipsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9)
.addComponent(policyComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(ramSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
okButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/ok.png"))); // NOI18N
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(okButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(okButton)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Changes the amount of virtual machines whenever the state of the Amount
* spinner changes.
*
* @param evt a change event.
* @since 1.0
*/
private void amountSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_amountSpinnerStateChanged
String n = String.valueOf(amountSpinner.getValue());
getVmr().setAmount(Integer.valueOf(n));
}//GEN-LAST:event_amountSpinnerStateChanged
/**
* Changes the image size of this virtual machine registry whenever the
* state of the Image Size spinner changes.
*
* @param evt a change event.
* @since 1.0
*/
private void imageSizeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_imageSizeSpinnerStateChanged
String n = String.valueOf(imageSizeSpinner.getValue());
getVmr().setSize(Long.valueOf(n));
}//GEN-LAST:event_imageSizeSpinnerStateChanged
/**
* Changes the number of processing elements of this virtual machine
* registry whenever the state of the PE number spinner changes.
*
* @param evt a change event.
* @since 1.0
*/
private void pesSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_pesSpinnerStateChanged
String n = String.valueOf(pesSpinner.getValue());
getVmr().setPesNumber(Integer.valueOf(n));
}//GEN-LAST:event_pesSpinnerStateChanged
/**
* Changes the number of mips of this virtual machine
* registry whenever the state of the mips spinner changes.
*
* @param evt a change event.
* @since 1.0
*/
private void mipsSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_mipsSpinnerStateChanged
String n = String.valueOf(mipsSpinner.getValue());
getVmr().setMips(Double.valueOf(n));
}//GEN-LAST:event_mipsSpinnerStateChanged
/**
* Changes the amount of RAM of this virtual machine
* registry whenever the state of the RAM spinner changes.
*
* @param evt a change event.
* @since 1.0
*/
private void ramSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_ramSpinnerStateChanged
String n = String.valueOf(ramSpinner.getValue());
getVmr().setRam(Integer.valueOf(n));
}//GEN-LAST:event_ramSpinnerStateChanged
/**
* Changes the amount of bandwidth of this virtual machine
* registry whenever the state of the bandwidth spinner changes.
*
* @param evt a change event.
* @since 1.0
*/
private void bwSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_bwSpinnerStateChanged
String n = String.valueOf(bwSpinner.getValue());
getVmr().setBw(Long.valueOf(n));
}//GEN-LAST:event_bwSpinnerStateChanged
/**
* Changes the priority of this virtual machine
* registry whenever the state of the priority spinner changes.
*
* @param evt a change event.
* @since 1.0
*/
private void prioritySpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_prioritySpinnerStateChanged
String n = String.valueOf(prioritySpinner.getValue());
getVmr().setPriority(Integer.valueOf(n));
}//GEN-LAST:event_prioritySpinnerStateChanged
/**
* Changes the hypervisor of this virtual machine registry whenever the
* item of the hypervisor combo box changes.
*
* @param evt an item event.
* @since 1.0
*/
private void hypervisorComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_hypervisorComboBoxItemStateChanged
switch(hypervisorComboBox.getSelectedIndex()) {
case 1:
getVmr().setVmm("KVM");
break;
default: //case 0:
getVmr().setVmm("Xen");
}
}//GEN-LAST:event_hypervisorComboBoxItemStateChanged
/**
* Changes the scheduling policy of this virtual machine registry whenever
* the item of the policy combo box changes.
*
* @param evt an item event.
* @since 1.0
*/
private void policyComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_policyComboBoxItemStateChanged
getVmr().setSchedulingPolicyAlias(policyComboBox.getSelectedItem().toString());
}//GEN-LAST:event_policyComboBoxItemStateChanged
/**
* Updates the virtual machine registry and the specific customer view when
* the OK button is clicked.
*
* @param evt an action event.
* @since 1.0
*/
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
vrDAO.updateVirtualMachineRegistry(getVmr());
//Get updated version of the customer registry
CustomerRegistryDAO crDAO = new CustomerRegistryDAO();
CustomerRegistry cr = crDAO.getCustomerRegistry(scv.getCustomerRegistry().getId());
//Updates the View reference
scv.setCustomerRegistry(cr);
scv.updateVmsTable();
MainView.setUserGroupModified(true);
dispose();
}//GEN-LAST:event_okButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JSpinner amountSpinner;
private javax.swing.JSpinner bwSpinner;
private javax.swing.JComboBox hypervisorComboBox;
private javax.swing.JSpinner imageSizeSpinner;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JSpinner jSpinner6;
private javax.swing.JSpinner mipsSpinner;
private javax.swing.JButton okButton;
private javax.swing.JSpinner pesSpinner;
private javax.swing.JComboBox policyComboBox;
private javax.swing.JSpinner prioritySpinner;
private javax.swing.JSpinner ramSpinner;
// End of variables declaration//GEN-END:variables
}