Skip to content

Commit

Permalink
Actividad 7
Browse files Browse the repository at this point in the history
  • Loading branch information
luisagalva committed Jan 12, 2018
1 parent f9307ca commit 2c0cb5b
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 131 deletions.
Binary file removed bin/Cloud/Exceptions/CloudGenericException.class
Binary file not shown.
Binary file modified bin/cloud/HardDiskDrive.class
Binary file not shown.
Binary file modified bin/cloud/Main.class
Binary file not shown.
Binary file modified bin/cloud/NetworkCard.class
Binary file not shown.
Binary file modified bin/cloud/VirtualMachine.class
Binary file not shown.
Binary file modified bin/cloud/util/CloudUtil.class
Binary file not shown.
12 changes: 0 additions & 12 deletions src/Cloud/Exceptions/CloudGenericException.java

This file was deleted.

14 changes: 2 additions & 12 deletions src/cloud/HardDiskDrive.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package Cloud;
import Cloud.Exceptions.*;

public class HardDiskDrive {
String id; // Identificador único
Expand All @@ -20,20 +19,11 @@ public HardDiskDrive(long capacityGB, int unitNumber){
// Escribe tu código {
StringBuilder sb = new StringBuilder().append("Hard Disk ").append(unitNumber);
this.label = sb.toString();

if(unitNumber>=0 || unitNumber%40!=0){
if(unitNumber>=0 && unitNumber%40!=0){

System.err.println("Unit Number debe ser mayor a 0 y multiplo de 40");
}
try {
if(capacityGB<1){

throw new CloudGenericException("CapacityGB debe ser mayor a 1GB");
}
}catch (CloudGenericException e) {
// TODO Auto-generated catch block
System.out.println("Error: "+e.toString());
}

this.capacityGB = capacityGB;
// }
}
Expand Down
59 changes: 37 additions & 22 deletions src/cloud/Main.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
package Cloud;

import java.io.IOException;
import java.util.HashMap;

public class Main {
// Método principal
public static void main(String[] args) {

// 1. Crear objeto vm1 basado en VirtualMachine
// Escribe tu código {

VirtualMachine vm1 = new VirtualMachine(1, 1024, "VM1", "Ubuntu");

int[] memories = {0, 1024, 2048, 4096,0};
int[] cpus = {2, 1, 0, 2,0};
int[] disks = {10, 0, 40, 10,0};
String[] os = {"Ubuntu", "CentOS", "Windows", "OSX",""};
// }
NetworkCard nic1 = new NetworkCard("122.22.22.22", 1);
NetworkCard nic2 = new NetworkCard("133.33.33.33", 2, 1000);

for (int i=0; i<=4; i++){
CreateVM(memories[i],cpus[i],disks[i],i,os[i]);
}
// 2. Crear un HashMap<Integer, NetworkCard> para agregar los
// objetos nic1 y nic2 creados previamente
// Escribe tu código {

HashMap<Integer, NetworkCard> nics = new HashMap<Integer, NetworkCard>();
nics.put(nic1.unitNumber, nic1);
nics.put(nic2.unitNumber, nic1);
// }

}

public static void CreateVM(int memory, int cpu, int diskCapacity, int suffix, String os){

VirtualMachine vm1;

vm1 = new VirtualMachine(cpu, memory, "VirtualMachine_" + suffix, os);
NetworkCard nic1 = new NetworkCard("122.22.22.22", 1);
vm1.addNIC(nic1);
HardDiskDrive hdd1 = new HardDiskDrive(diskCapacity, 1);
vm1.addHDD(hdd1);
HardDiskDrive hdd1 = new HardDiskDrive(100, 1);
HardDiskDrive hdd2 = new HardDiskDrive(120, 2);

// 3. Crear un HashMap<Integer, HardDiskDrive> para agregar los
// objetos hdd1 y hdd1 creados previamente
// Escribe tu código {
HashMap<Integer, HardDiskDrive> hdds = new HashMap<Integer, HardDiskDrive>();
hdds.put(hdd1.unitNumber, hdd1);
hdds.put(hdd2.unitNumber, hdd1);
// }

// 4. Asignar nics y hdds a VirtualMachine.nics y
// VirtualMachine.hdds respectivamente
// Escribe tu código {
vm1.addNICs(nics);
vm1.addHDDs(hdds);
// }

// 5. Imprimiendo variables de VM1
System.out.println("Resumen: ");
System.out.println(vm1.toString());

// 6. Imprimiendo variables de VM1.nics
System.out.println("Detallado NICs: ");
System.out.println(nic1.toString());
System.out.println(nic2.toString());
// Escribe tu código {

// }

// 7. Imprimiendo variables de VM1.hdds
System.out.println("Detallado HDDs: ");
System.out.println(hdd1.toString());
System.out.println(hdd2.toString());
// Escribe tu código {




// }
}


Expand Down
28 changes: 1 addition & 27 deletions src/cloud/NetworkCard.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package Cloud;


import Cloud.Util.CloudUtil;
import Cloud.Exceptions.*;
import java.lang.*;

public class NetworkCard {
public static final int MAX_SPEED_MB = 100;
Expand All @@ -19,15 +18,6 @@ public class NetworkCard {
* Constructores
*/
NetworkCard(int unitNumber){
if(unitNumber<1){
try {
throw new CloudGenericException("Unit number debe ser mayor a 0");
} catch (CloudGenericException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

this.unitNumber = unitNumber;
// Escribe tu código {
StringBuilder sb = new StringBuilder().append("Network Card").append(unitNumber);
Expand All @@ -38,14 +28,6 @@ public class NetworkCard {

NetworkCard(String network, int unitNumber){
this.network = network;
if(unitNumber<1){
try {
throw new CloudGenericException("Unit number debe ser mayor a 0");
} catch (CloudGenericException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.unitNumber = unitNumber;
// Escribe tu código {
StringBuilder sb = new StringBuilder().append("Network Card").append(unitNumber);
Expand All @@ -55,14 +37,6 @@ public class NetworkCard {
}
NetworkCard(String network, int unitNumber, int speedMb){
this.network = network;
if(unitNumber<1){
try {
throw new CloudGenericException("Unit number debe ser mayor a 0");
} catch (CloudGenericException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.unitNumber = unitNumber;
this.speedMb = speedMb;
// Escribe tu código {
Expand Down
91 changes: 35 additions & 56 deletions src/cloud/VirtualMachine.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package Cloud;

import java.util.HashMap;

import java.lang.*;

import Cloud.Util.CloudUtil;
import Cloud.Exceptions.CloudGenericException;
import java.io.IOException;

public class VirtualMachine {
final String id; // Identificador único
Expand Down Expand Up @@ -39,34 +37,21 @@ public class VirtualMachine {
*/
VirtualMachine(int cpuCount, long memoryGB, String guestOS){
// Escribe tu código {
try {
if(cpuCount<=0){

throw new CloudGenericException("Cpu count debe ser mayor a 0");
}
else{

this.cpuCount = cpuCount;
}
} catch (CloudGenericException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if(cpuCount<=0){
this.cpuCount = 1;
System.err.println("Cpu count debe ser mayor a 0");
}
else{

this.cpuCount = cpuCount;
}

try{
if(memoryGB<1){

throw new CloudGenericException("MemoryGB debe ser mayor 1");
}
if(memoryGB>=1024 && memoryGB%1024 == 0){
this.memoryGB = memoryGB;}
else{
this.memoryGB = memoryGB;
}
}catch (CloudGenericException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}

this.memoryGB = 1024;
System.err.println("MemoryGB debe ser mayor a 1024 o un múltiplo de 1024"); }

if(guestOS.length()>=5){
this.guestOS = guestOS;
Expand All @@ -76,40 +61,34 @@ public class VirtualMachine {
System.err.println("guestOS debe ser mayor a 5 caracteres");
}


// }
this.id = CloudUtil.getUUID();
}

VirtualMachine(int cpuCount, long memoryGB, String name, String guestOS) {
try {
if(cpuCount>0){
this.cpuCount = cpuCount;
}
else{

throw new CloudGenericException("Cpu debe ser mayor a 0");
}
} catch (CloudGenericException e) {
// TODO Auto-generated catch block
System.out.println("Error: "+e.toString());
}


try{
if(memoryGB<1){

throw new CloudGenericException("Memoria debe ser mayor o igual a 1024");
}

this.memoryGB = memoryGB;
}catch (CloudGenericException e) {
// TODO Auto-generated catch block

System.out.println("Error: "+e.toString());
VirtualMachine(int cpuCount, long memoryGB, String name, String guestOS){
// Escribe tu código {
if(cpuCount<=0){
this.cpuCount = 1;
System.err.println("Cpu count debe ser mayor a 0");
}
else{
this.cpuCount = cpuCount;
}

}
this.guestOS = guestOS;
if(memoryGB>=1024 && memoryGB%1024 == 0){
this.memoryGB = memoryGB;}
else{

this.memoryGB = 1024;
System.err.println("MemoryGB debe ser mayor a 1024 o un múltiplo de 1024"); }

if(guestOS.length()>=5){
this.guestOS = guestOS;
}
else{
this.guestOS = guestOS;
System.err.println("guestOS debe ser mayor a 5 caracteres");
}
if(name.length()>=5){
this.name = name;
}
Expand Down
2 changes: 0 additions & 2 deletions src/cloud/util/CloudUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package Cloud.Util;



import java.util.Random;
import java.util.UUID;

Expand Down

0 comments on commit 2c0cb5b

Please sign in to comment.