Skip to content

Commit

Permalink
Actividad 8
Browse files Browse the repository at this point in the history
  • Loading branch information
luisagalva committed Jan 12, 2018
1 parent c43cc8b commit f9307ca
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 82 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified bin/.DS_Store
Binary file not shown.
Binary file added 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: 12 additions & 0 deletions src/Cloud/Exceptions/CloudGenericException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Cloud.Exceptions;

public class CloudGenericException extends Exception {

public CloudGenericException(String message){
super(message);
}

public CloudGenericException(){
super();
}
}
16 changes: 13 additions & 3 deletions src/cloud/HardDiskDrive.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package cloud;
package Cloud;
import Cloud.Exceptions.*;

public class HardDiskDrive {
String id; // Identificador único
Expand All @@ -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;
// }
}
Expand Down
61 changes: 23 additions & 38 deletions src/cloud/Main.java
Original file line number Diff line number Diff line change
@@ -1,66 +1,51 @@
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<Integer, NetworkCard> 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<Integer, NetworkCard> nics = new HashMap<Integer, NetworkCard>();
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<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);
// }

}

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());

// 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
32 changes: 29 additions & 3 deletions src/cloud/NetworkCard.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand Down
95 changes: 58 additions & 37 deletions src/cloud/VirtualMachine.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/cloud/util/CloudUtil.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package cloud.util;
package Cloud.Util;



import java.util.Random;
import java.util.UUID;
Expand Down

0 comments on commit f9307ca

Please sign in to comment.