diff --git a/.DS_Store b/.DS_Store index 7a83e0c..065826e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/bin/.DS_Store b/bin/.DS_Store index bbe7a4e..ad9c748 100644 Binary files a/bin/.DS_Store and b/bin/.DS_Store differ diff --git a/bin/Cloud/Exceptions/CloudGenericException.class b/bin/Cloud/Exceptions/CloudGenericException.class new file mode 100644 index 0000000..d4579a3 Binary files /dev/null and b/bin/Cloud/Exceptions/CloudGenericException.class differ diff --git a/bin/cloud/HardDiskDrive.class b/bin/cloud/HardDiskDrive.class index e4b9324..cac3f30 100644 Binary files a/bin/cloud/HardDiskDrive.class and b/bin/cloud/HardDiskDrive.class differ diff --git a/bin/cloud/Main.class b/bin/cloud/Main.class index dea2510..5353850 100644 Binary files a/bin/cloud/Main.class and b/bin/cloud/Main.class differ diff --git a/bin/cloud/NetworkCard.class b/bin/cloud/NetworkCard.class index a4aa73a..4202d01 100644 Binary files a/bin/cloud/NetworkCard.class and b/bin/cloud/NetworkCard.class differ diff --git a/bin/cloud/VirtualMachine.class b/bin/cloud/VirtualMachine.class index 47fb47a..fe2969b 100644 Binary files a/bin/cloud/VirtualMachine.class and b/bin/cloud/VirtualMachine.class differ diff --git a/bin/cloud/util/CloudUtil.class b/bin/cloud/util/CloudUtil.class index 2f698e3..a700f8a 100644 Binary files a/bin/cloud/util/CloudUtil.class and b/bin/cloud/util/CloudUtil.class differ diff --git a/src/Cloud/Exceptions/CloudGenericException.java b/src/Cloud/Exceptions/CloudGenericException.java new file mode 100644 index 0000000..e3db588 --- /dev/null +++ b/src/Cloud/Exceptions/CloudGenericException.java @@ -0,0 +1,12 @@ +package Cloud.Exceptions; + +public class CloudGenericException extends Exception { + + public CloudGenericException(String message){ + super(message); + } + + public CloudGenericException(){ + super(); + } +} diff --git a/src/cloud/HardDiskDrive.java b/src/cloud/HardDiskDrive.java index 652ef0f..b8247eb 100644 --- a/src/cloud/HardDiskDrive.java +++ b/src/cloud/HardDiskDrive.java @@ -1,4 +1,5 @@ -package cloud; +package Cloud; +import Cloud.Exceptions.*; public class HardDiskDrive { String id; // Identificador único @@ -19,11 +20,20 @@ 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; // } } diff --git a/src/cloud/Main.java b/src/cloud/Main.java index 5278fd4..0bcb66c 100644 --- a/src/cloud/Main.java +++ b/src/cloud/Main.java @@ -1,47 +1,33 @@ -package cloud; +package Cloud; -import java.util.HashMap; +import java.io.IOException; 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"); - // } - NetworkCard nic1 = new NetworkCard("122.22.22.22", 1); - NetworkCard nic2 = new NetworkCard("133.33.33.33", 2, 1000); + 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",""}; - // 2. Crear un HashMap para agregar los - // objetos nic1 y nic2 creados previamente - // Escribe tu código { + for (int i=0; i<=4; i++){ + CreateVM(memories[i],cpus[i],disks[i],i,os[i]); + } - HashMap nics = new HashMap(); - nics.put(nic1.unitNumber, nic1); - nics.put(nic2.unitNumber, nic1); - // } - HardDiskDrive hdd1 = new HardDiskDrive(100, 1); - HardDiskDrive hdd2 = new HardDiskDrive(120, 2); - - // 3. Crear un HashMap para agregar los - // objetos hdd1 y hdd1 creados previamente - // Escribe tu código { - HashMap hdds = new HashMap(); - 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); - // } - + } + + 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); // 5. Imprimiendo variables de VM1 System.out.println("Resumen: "); System.out.println(vm1.toString()); @@ -49,7 +35,6 @@ public static void main(String[] args) { // 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 { // } @@ -57,10 +42,10 @@ public static void main(String[] args) { // 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 { - // } + + + } diff --git a/src/cloud/NetworkCard.java b/src/cloud/NetworkCard.java index aeb5de3..06477af 100644 --- a/src/cloud/NetworkCard.java +++ b/src/cloud/NetworkCard.java @@ -1,7 +1,8 @@ -package cloud; +package Cloud; -import cloud.util.CloudUtil; -import java.lang.*; + +import Cloud.Util.CloudUtil; +import Cloud.Exceptions.*; public class NetworkCard { public static final int MAX_SPEED_MB = 100; @@ -18,6 +19,15 @@ 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); @@ -28,6 +38,14 @@ 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); @@ -37,6 +55,14 @@ 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 { diff --git a/src/cloud/VirtualMachine.java b/src/cloud/VirtualMachine.java index 67d3ef3..282a84e 100644 --- a/src/cloud/VirtualMachine.java +++ b/src/cloud/VirtualMachine.java @@ -1,9 +1,11 @@ -package cloud; +package Cloud; import java.util.HashMap; -import java.lang.*; -import cloud.util.CloudUtil; + +import Cloud.Util.CloudUtil; +import Cloud.Exceptions.CloudGenericException; +import java.io.IOException; public class VirtualMachine { final String id; // Identificador único @@ -37,21 +39,34 @@ public class VirtualMachine { */ VirtualMachine(int cpuCount, long memoryGB, String guestOS){ // Escribe tu código { - if(cpuCount<=0){ - this.cpuCount = 1; - System.err.println("Cpu count debe ser mayor a 0"); - } - else{ + 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(); - this.cpuCount = cpuCount; } - if(memoryGB>=1024 && memoryGB%1024 == 0){ - this.memoryGB = memoryGB;} + try{ + if(memoryGB<1){ + + throw new CloudGenericException("MemoryGB debe ser mayor 1"); + } else{ - - this.memoryGB = 1024; - System.err.println("MemoryGB debe ser mayor a 1024 o un múltiplo de 1024"); } + this.memoryGB = memoryGB; + } + }catch (CloudGenericException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + + } if(guestOS.length()>=5){ this.guestOS = guestOS; @@ -61,34 +76,40 @@ 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){ - // Escribe tu código { - if(cpuCount<=0){ - this.cpuCount = 1; - System.err.println("Cpu count debe ser mayor a 0"); - } - else{ - this.cpuCount = cpuCount; - } - - if(memoryGB>=1024 && memoryGB%1024 == 0){ - this.memoryGB = memoryGB;} - else{ + 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 = 1024; - System.err.println("MemoryGB debe ser mayor a 1024 o un múltiplo de 1024"); } + this.memoryGB = memoryGB; + }catch (CloudGenericException e) { + // TODO Auto-generated catch block + + System.out.println("Error: "+e.toString()); + + } + this.guestOS = guestOS; - 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; } diff --git a/src/cloud/util/CloudUtil.java b/src/cloud/util/CloudUtil.java index 52c5c7b..65c98df 100644 --- a/src/cloud/util/CloudUtil.java +++ b/src/cloud/util/CloudUtil.java @@ -1,4 +1,6 @@ -package cloud.util; +package Cloud.Util; + + import java.util.Random; import java.util.UUID;