Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import javax.swing.table.AbstractTableModel;
- import org.cloudbus.cloudsim.Cloudlet;
- import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared;
- import org.cloudbus.cloudsim.DatacenterCharacteristics;
- import org.cloudbus.cloudsim.HarddriveStorage;
- import org.cloudbus.cloudsim.Host;
- import org.cloudbus.cloudsim.Log;
- import org.cloudbus.cloudsim.Pe;
- import org.cloudbus.cloudsim.Storage;
- import org.cloudbus.cloudsim.VmAllocationPolicySimple;
- import org.cloudbus.cloudsim.VmSchedulerTimeShared;
- import org.cloudbus.cloudsim.core.CloudSim;
- import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
- import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
- import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
- import org.workflowsim.CondorVM;
- import org.workflowsim.Job;
- import org.workflowsim.WorkflowDatacenter;
- import org.workflowsim.WorkflowEngine;
- import org.workflowsim.WorkflowPlanner;
- import org.workflowsim.utils.ClusteringParameters;
- import org.workflowsim.utils.OverheadParameters;
- import org.workflowsim.utils.Parameters;
- import org.workflowsim.utils.ReplicaCatalog;
- import javax.swing.filechooser.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.image.BufferedImage;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.LinkedList;
- import java.util.List;
- public class test extends WindowAdapter
- implements ActionListener {
- private Point lastLocation = null;
- private int maxX = 500;
- private int maxY = 500;
- private boolean DEBUG = false;
- static private final String newline = "\n";
- private static JButton defaultButton = null;
- protected static String VM = "";
- protected static int vm1 = 10;
- protected final static String LF_DECORATIONS = "laf_dec";
- protected final static String WS_DECORATIONS = "ws_dec";
- protected final static String CREATE_WINDOW = "new_win";
- protected final static String TEST_FILE = "test";
- protected final static String NASTAV = "test";
- protected final static String ROUND_ROBIN = "round_robin";
- protected final static String MAX_MIN = "max_min";
- protected final static String MIN_MIN = "min_min";
- protected static String CESTA = "E:/Documents and Settings/zais/Dokumenty/WorkflowSim-1.0-master/config/dax/Montage_100.xml";
- protected boolean roundrobin = true;
- protected boolean maxmin = false;
- protected boolean minmin = false;
- JFileChooser fc;
- JTextArea log;
- JTextField vm;
- //static JTextField textField;
- public test() {
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- maxX = screenSize.width - 50;
- maxY = screenSize.height - 50;
- }
- // FUNKCIA KTORA SA VYKONA PO KLIKNUTI
- public void simulate() throws IOException {
- if(roundrobin==true)
- {
- RoundRobin();
- vysledok1();
- }
- if(maxmin==true)
- {
- maxmin();
- vysledok1();
- }
- if(minmin==true)
- {
- minmin();
- vysledok1();
- }
- }
- // RoundRobin
- private void RoundRobin() {
- try {
- // Prvý krok. Inicializácia workflow.
- int vmNum = 10;//počet Virtuálnych strojov
- String daxPath = CESTA;
- File daxFile = new File(daxPath);
- if (!daxFile.exists()) {
- Log.printLine("Nastavte adresu k súboru, ktorý obsahuje testovacie úlohy.");
- return;
- }
- Parameters.SchedulingAlgorithm sch_method = Parameters.SchedulingAlgorithm.ROUNDROBIN;
- Parameters.PlanningAlgorithm pln_method = Parameters.PlanningAlgorithm.INVALID;
- ReplicaCatalog.FileSystem file_system = ReplicaCatalog.FileSystem.LOCAL;
- OverheadParameters op = new OverheadParameters(0, null, null, null, null, 0);
- ClusteringParameters.ClusteringMethod method = ClusteringParameters.ClusteringMethod.NONE;
- ClusteringParameters cp = new ClusteringParameters(0, 0, method, null);
- Parameters.init(vmNum, daxPath, null,
- null, op, cp, sch_method, pln_method,
- null, 0);
- ReplicaCatalog.init(file_system);
- int num_user = 1;
- Calendar calendar = Calendar.getInstance();
- boolean trace_flag = false;
- CloudSim.init(num_user, calendar, trace_flag);
- WorkflowDatacenter datacenter0 = createDatacenter("Datacenter_0");
- WorkflowPlanner wfPlanner = new WorkflowPlanner("planner_0", 1);
- WorkflowEngine wfEngine = wfPlanner.getWorkflowEngine();
- List<CondorVM> vmlist0 = createVM(wfEngine.getSchedulerId(0), Parameters.getVmNum());
- wfEngine.submitVmList(vmlist0, 0);
- wfEngine.bindSchedulerDatacenter(datacenter0.getId(), 0);
- CloudSim.startSimulation();
- List<Job> outputList0 = wfEngine.getJobsReceivedList();
- CloudSim.stopSimulation();
- printJobList(outputList0);
- } catch (Exception e) {
- Log.printLine("Simulácia skončila nečakanou chybou.");
- }
- }
- //MinMin
- private void minmin() {
- try {
- // Prvý krok. Inicializácia workflow.
- int vmNum = 10;//počet Virtuálnych strojov
- String daxPath = CESTA;
- File daxFile = new File(daxPath);
- if (!daxFile.exists()) {
- Log.printLine("Nastavte adresu k súboru, ktorý obsahuje testovacie úlohy.");
- return;
- }
- Parameters.SchedulingAlgorithm sch_method = Parameters.SchedulingAlgorithm.MINMIN;
- Parameters.PlanningAlgorithm pln_method = Parameters.PlanningAlgorithm.INVALID;
- ReplicaCatalog.FileSystem file_system = ReplicaCatalog.FileSystem.LOCAL;
- OverheadParameters op = new OverheadParameters(0, null, null, null, null, 0);
- ClusteringParameters.ClusteringMethod method = ClusteringParameters.ClusteringMethod.NONE;
- ClusteringParameters cp = new ClusteringParameters(0, 0, method, null);
- Parameters.init(vmNum, daxPath, null,
- null, op, cp, sch_method, pln_method,
- null, 0);
- ReplicaCatalog.init(file_system);
- int num_user = 1;
- Calendar calendar = Calendar.getInstance();
- boolean trace_flag = false;
- CloudSim.init(num_user, calendar, trace_flag);
- WorkflowDatacenter datacenter0 = createDatacenter("Datacenter_0");
- WorkflowPlanner wfPlanner = new WorkflowPlanner("planner_0", 1);
- WorkflowEngine wfEngine = wfPlanner.getWorkflowEngine();
- List<CondorVM> vmlist0 = createVM(wfEngine.getSchedulerId(0), Parameters.getVmNum());
- wfEngine.submitVmList(vmlist0, 0);
- wfEngine.bindSchedulerDatacenter(datacenter0.getId(), 0);
- CloudSim.startSimulation();
- List<Job> outputList0 = wfEngine.getJobsReceivedList();
- CloudSim.stopSimulation();
- printJobList(outputList0);
- } catch (Exception e) {
- Log.printLine("Simulácia skončila nečakanou chybou.");
- }
- }
- //MaxMin
- private void maxmin() {
- try {
- // Prvý krok. Inicializácia workflow.
- int vmNum = 10;//počet Virtuálnych strojov
- String daxPath = CESTA;
- File daxFile = new File(daxPath);
- if (!daxFile.exists()) {
- Log.printLine("Nastavte adresu k súboru, ktorý obsahuje testovacie úlohy.");
- return;
- }
- Parameters.SchedulingAlgorithm sch_method = Parameters.SchedulingAlgorithm.MAXMIN;
- Parameters.PlanningAlgorithm pln_method = Parameters.PlanningAlgorithm.INVALID;
- ReplicaCatalog.FileSystem file_system = ReplicaCatalog.FileSystem.LOCAL;
- OverheadParameters op = new OverheadParameters(0, null, null, null, null, 0);
- ClusteringParameters.ClusteringMethod method = ClusteringParameters.ClusteringMethod.NONE;
- ClusteringParameters cp = new ClusteringParameters(0, 0, method, null);
- Parameters.init(vmNum, daxPath, null,
- null, op, cp, sch_method, pln_method,
- null, 0);
- ReplicaCatalog.init(file_system);
- int num_user = 1;
- Calendar calendar = Calendar.getInstance();
- boolean trace_flag = false;
- CloudSim.init(num_user, calendar, trace_flag);
- WorkflowDatacenter datacenter0 = createDatacenter("Datacenter_0");
- WorkflowPlanner wfPlanner = new WorkflowPlanner("planner_0", 1);
- WorkflowEngine wfEngine = wfPlanner.getWorkflowEngine();
- List<CondorVM> vmlist0 = createVM(wfEngine.getSchedulerId(0), Parameters.getVmNum());
- wfEngine.submitVmList(vmlist0, 0);
- wfEngine.bindSchedulerDatacenter(datacenter0.getId(), 0);
- CloudSim.startSimulation();
- List<Job> outputList0 = wfEngine.getJobsReceivedList();
- CloudSim.stopSimulation();
- printJobList(outputList0);
- } catch (Exception e) {
- Log.printLine("Simulácia skončila nečakanou chybou.");
- }
- }
- // VYPIS
- protected static void printJobList(List<Job> list) throws IOException {
- int size = list.size();
- Job job;
- String file ="E:/priebeh.txt";
- FileWriter fw = new FileWriter (file);
- BufferedWriter bw = new BufferedWriter (fw);
- PrintWriter priebeh = new PrintWriter (bw);
- DecimalFormat dft = new DecimalFormat("###.##");
- for (int i = 0; i < size; i++) {
- job = list.get(i);
- priebeh.println(job.getCloudletId());
- if (job.getCloudletStatus() == Cloudlet.SUCCESS) {
- priebeh.println("SPLNENA");
- priebeh.println(job.getResourceId());
- priebeh.println(job.getVmId());
- priebeh.println(dft.format(job.getActualCPUTime()));
- priebeh.println(dft.format(job.getExecStartTime()));
- priebeh.println(dft.format(job.getFinishTime()));
- priebeh.println(job.getDepth());
- } else if (job.getCloudletStatus() == Cloudlet.FAILED) {
- priebeh.println("NEUSPECH");
- priebeh.println(job.getResourceId());
- priebeh.println(job.getVmId());
- priebeh.println(dft.format(job.getActualCPUTime()));
- priebeh.println(dft.format(job.getExecStartTime()));
- priebeh.println(dft.format(job.getFinishTime()));
- priebeh.println(job.getDepth());
- }
- }
- priebeh.close();
- }
- // VYTVORENIE DATACENTRA
- protected static WorkflowDatacenter createDatacenter(String name) {
- List<Host> hostList = new ArrayList<>();
- for (int i = 1; i <= 20; i++) {
- List<Pe> peList1 = new ArrayList<>();
- int mips = 2000;
- peList1.add(new Pe(0, new PeProvisionerSimple(mips)));
- peList1.add(new Pe(1, new PeProvisionerSimple(mips)));
- int hostId = 0;
- int ram = 2048;
- long storage = 1000000;
- int bw = 10000;
- hostList.add(
- new Host(
- hostId,
- new RamProvisionerSimple(ram),
- new BwProvisionerSimple(bw),
- storage,
- peList1,
- new VmSchedulerTimeShared(peList1)));
- hostId++;
- }
- String arch = "x86";
- String os = "Linux";
- String vmm = "Xen";
- double time_zone = 10.0;
- double cost = 3.0;
- double costPerMem = 0.05;
- double costPerStorage = 0.1;
- double costPerBw = 0.1;
- LinkedList<Storage> storageList = new LinkedList<>();
- WorkflowDatacenter datacenter = null;
- DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
- arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
- int maxTransferRate = 15;
- try {
- HarddriveStorage s1 = new HarddriveStorage(name, 1e12);
- s1.setMaxTransferRate(maxTransferRate);
- storageList.add(s1);
- datacenter = new WorkflowDatacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return datacenter;
- }
- // VYTVORENIE VIRTUALNEHO STROJA
- protected static List<CondorVM> createVM(int userId, int vms) {
- LinkedList<CondorVM> list = new LinkedList<>();
- long size = 10000;
- int ram = 512;
- int mips = 1000;
- long bw = 1000;
- int pesNumber = 1;
- String vmm = "Xen";
- CondorVM[] vm = new CondorVM[vms];
- for (int i = 0; i < vms; i++) {
- double ratio = 1.0;
- vm[i] = new CondorVM(i, userId, mips * ratio, pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared());
- list.add(vm[i]);
- }
- return list;
- }
- // VYTVORENIE TLACITIEK
- protected JComponent createOptionControls() {
- fc = new JFileChooser();
- log = new JTextArea(5, 20);
- log.setMargin(new Insets(5,5,5,5));
- log.setEditable(false);
- JScrollPane logScrollPane = new JScrollPane(log);
- JLabel label = new JLabel("Počet Virtuálnych Strojov:");
- JLabel label1 = new JLabel("Testovací súbor:");
- JLabel label2 = new JLabel("Algoritmus:");
- JTextField vm = new JTextField(6);
- vm = new JTextField();
- vm.setActionCommand(VM);
- vm.addActionListener(this);
- JButton nastav = new JButton("Test ...");
- nastav.setActionCommand(NASTAV);
- nastav.addActionListener(this);
- JButton otvor = new JButton("Test ...");
- otvor.setActionCommand(TEST_FILE);
- otvor.addActionListener(this);
- ButtonGroup bg2 = new ButtonGroup();
- //
- //
- JRadioButton rb4 = new JRadioButton();
- rb4.setText("RoundRobin");
- rb4.setActionCommand(ROUND_ROBIN);
- rb4.addActionListener(this);
- rb4.setSelected(true);
- bg2.add(rb4);
- //
- JRadioButton rb5 = new JRadioButton();
- rb5.setText("MinMax");
- rb5.setActionCommand(MAX_MIN);
- rb5.addActionListener(this);
- bg2.add(rb5);
- //
- JRadioButton rb6 = new JRadioButton();
- rb6.setText("MaxMin");
- rb6.setActionCommand(MIN_MIN);
- rb6.addActionListener(this);
- bg2.add(rb6);
- //Pridanie všetkého do kontajnera
- Box box = Box.createVerticalBox();
- box.add(Box.createVerticalStrut(15));
- box.add(Box.createVerticalStrut(15));
- box.add(label);
- box.add(Box.createVerticalStrut(15));
- box.add(vm);
- box.add(Box.createVerticalStrut(15));
- box.add(label1);
- box.add(Box.createVerticalStrut(15));
- box.add(otvor);
- box.add(Box.createVerticalStrut(15));
- box.add(label2);
- box.add(Box.createVerticalStrut(5));
- box.add(rb4);
- box.add(rb5);
- box.add(rb6);
- box.add(Box.createVerticalStrut(15));
- box.add(logScrollPane);
- return box;
- }
- // CITANIE SUBORU
- protected JComponent vypis() {
- JLabel label1 = new JLabel("Priebeh");
- JTable table = new JTable(new MyTableModel());
- table.setPreferredScrollableViewportSize(new Dimension(500, 500));
- table.setFillsViewportHeight(true);
- JScrollPane scrollPane = new JScrollPane(table);
- table.setFillsViewportHeight(true);
- //Pridanie všetkého do kontajnera
- Box box = Box.createVerticalBox();
- box.add(label1);
- String file ="E:/priebeh.txt";
- //Citanie
- try{
- InputStream ips=new FileInputStream(file);
- InputStreamReader ipsr=new InputStreamReader(ips);
- BufferedReader br=new BufferedReader(ipsr);
- String line;
- Integer i=2;
- while ((line=br.readLine())!=null){
- JLabel label2 = new JLabel(line);
- box.add(label2);
- i++;
- }
- br.close();
- }
- catch (Exception e){
- System.out.println(e.toString());
- }
- //
- box.add(Box.createVerticalStrut(15));
- return box;
- }
- // TABULKA
- class MyTableModel extends AbstractTableModel {
- private String[] columnNames = {"ID úlohy",
- "STAV",
- "ID Dátového centra",
- "ID Virtuálneho stroja",
- "Čas",
- "Čas spustenia",
- "Čas dokončenia",
- "Hĺbka"
- };
- private Object[][] data = {{"", "", "", "", "", "", "", ""}};
- public int getColumnCount() {
- return columnNames.length;
- }
- public int getRowCount() {
- return data.length;
- }
- public String getColumnName(int col) {
- return columnNames[col];
- }
- public Object getValueAt(int row, int col) {
- return data[row][col];
- }
- public Class getColumnClass(int c) {
- return getValueAt(0, c).getClass();
- }
- public boolean isCellEditable(int row, int col) {
- if (col < 2) {
- return false;
- } else {
- return true;
- }
- }
- public void setValueAt(Object value, int row, int col) {
- if (DEBUG) {
- System.out.println("Setting value at " + row + "," + col
- + " to " + value
- + " (an instance of "
- + value.getClass() + ")");
- }
- data[row][col] = value;
- fireTableCellUpdated(row, col);
- if (DEBUG) {
- System.out.println("New value of data:");
- printDebugData();
- }
- }
- private void printDebugData() {
- int numRows = getRowCount();
- int numCols = getColumnCount();
- for (int i=0; i < numRows; i++) {
- System.out.print(" row " + i + ":");
- for (int j=0; j < numCols; j++) {
- System.out.print(" " + data[i][j]);
- }
- System.out.println();
- }
- System.out.println("--------------------------");
- }
- }
- // TLACITKO
- protected JComponent createButtonPane() {
- JButton button = new JButton("Simuluj");
- button.setActionCommand(CREATE_WINDOW);
- button.addActionListener(this);
- defaultButton = button;
- JPanel pane = new JPanel();
- pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
- pane.add(button);
- return pane;
- }
- // ODCHITAVANIE AKCIE
- public void actionPerformed(ActionEvent e) {
- String command = e.getActionCommand();
- if (TEST_FILE.equals(command)) {
- int returnVal = fc.showDialog(defaultButton, command);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- log.append("Nastavený testovací súbor: " + file.getPath() + "." + newline);
- CESTA = file.getPath();
- } else {
- log.append("Nastavenie súboru na testovenie bolo prerušené uživatelom.");
- }
- log.setCaretPosition(log.getDocument().getLength());
- }
- else if (CREATE_WINDOW.equals(command)) {
- try {
- simulate();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- else if (ROUND_ROBIN.equals(command)) {
- roundrobin = true;
- maxmin = false;
- minmin = false;
- log.append("Algoritmus : RoundRobin"+ newline);
- String VO = vm.getText();
- } else if (MAX_MIN.equals(command)) {
- roundrobin = false;
- maxmin = true;
- minmin = false;
- log.append("Algoritmus : MaxMin" + newline);
- } else if (MIN_MIN.equals(command)) {
- roundrobin = false;
- maxmin = false;
- minmin = true;
- log.append("Algoritmus : MinMin" + newline);
- }
- }
- // VYTVORENIE A ZOBRAZENIE PROSTREDIA
- private static void createAndShowGUI() {
- try {
- UIManager.setLookAndFeel(
- UIManager.getCrossPlatformLookAndFeelClassName());
- } catch (Exception e) { }
- JFrame.setDefaultLookAndFeelDecorated(true);
- JDialog.setDefaultLookAndFeelDecorated(true);
- JFrame frame = new JFrame("Simulátor");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Vytvorenie a nastavenie
- test demo = new test();
- //Pridanie komponentov.
- Container contentPane = frame.getContentPane();
- contentPane.add(demo.createOptionControls(),
- BorderLayout.CENTER);
- contentPane.add(demo.createButtonPane(),
- BorderLayout.PAGE_END);
- frame.getRootPane().setDefaultButton(defaultButton);
- //Zobrazenie okna
- frame.pack();
- frame.setLocationRelativeTo(null); // Centrovanie
- frame.setVisible(true);
- }
- // OKNO VYPISANIE
- private static void vysledok1() {
- try {
- UIManager.setLookAndFeel(
- UIManager.getCrossPlatformLookAndFeelClassName());
- } catch (Exception e) { }
- test demo = new test();
- JFrame frame = new JFrame("Výsledok");
- Container contentPane2 = frame.getContentPane();
- contentPane2.add(demo.vypis(),
- BorderLayout.CENTER);
- frame.pack();
- frame.setLocationRelativeTo(null); // Centrovanie
- frame.setVisible(true);
- }
- // MAIN
- public static void main(String[] args) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement