@Test public void testDeployVMsUsingDEMOImages() throws InterruptedException { DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); Deployment deployment = new Deployment(); deployment.setId(22); deployment.setOvf(threeTierWebAppDEMOOvfString); when(deploymentDAO.getById(22)).thenReturn(deployment); ApplicationDAO applicationDAO = mock(ApplicationDAO.class); Application application = new Application(); application.setName("threeTierWebApp"); when(applicationDAO.getByName("threeTierWebApp")).thenReturn(application); when(applicationDAO.update(application)).thenReturn(true); when(deploymentDAO.update(deployment)).thenReturn(true); VmManagerClient vmMaClient = mock(VmManagerClient.class); when(vmMaClient.uploadImage(eq(new ImageToUploadWithEquals("haproxy.img","/DFS/ascetic/vm-images/threeTierWebApp/haproxy.img")))).thenReturn("haproxy-uuid"); when(vmMaClient.uploadImage(eq(new ImageToUploadWithEquals("mysql.img","/DFS/ascetic/vm-images/threeTierWebApp/mysql.img")))).thenReturn("mysql-uuid"); when(vmMaClient.uploadImage(eq(new ImageToUploadWithEquals("jmeter.img","/DFS/ascetic/vm-images/threeTierWebApp/jmeter.img")))).thenReturn("jmeter-uuid"); List<Vm> vms1 = new ArrayList<Vm>(); VmWithEquals vm1 = new VmWithEquals("HAProxy_1","haproxy-uuid",1,1024,20, 0, "/DFS/ascetic/vm-images/threeTierWebApp/haproxy.iso_1","threeTierWebApp", "haproxy", "sla-id", false); vms1.add(vm1); List<String> ids1 = new ArrayList<String>(); ids1.add("haproxy-vm1"); when(vmMaClient.deployVMs(eq(vms1))).thenReturn(ids1); List<Vm> vms2 = new ArrayList<Vm>(); VmWithEquals vm2 = new VmWithEquals("Jboss_1","jboss-uuid",1,2048,20, 0, "/DFS/ascetic/vm-images/threeTierWebApp/jboss.iso_1","threeTierWebApp", "jboss", "sla-id", false); vms2.add(vm2); List<String> ids2 = new ArrayList<String>(); ids2.add("jboss-vm1"); when(vmMaClient.deployVMs(eq(vms2))).thenReturn(ids2); List<Vm> vms5 = new ArrayList<Vm>(); VmWithEquals vm5 = new VmWithEquals("Jboss_2","jboss-uuid",1,2048,20, 0, "/DFS/ascetic/vm-images/threeTierWebApp/jboss.iso_2","threeTierWebApp", "jboss", "sla-id", false); vms5.add(vm5); List<String> ids5 = new ArrayList<String>(); ids5.add("jboss-vm2"); when(vmMaClient.deployVMs(eq(vms5))).thenReturn(ids5); List<Vm> vms3 = new ArrayList<Vm>(); VmWithEquals vm3 = new VmWithEquals("MySQL_1","mysql-uuid",1,1024,20, 0, "/DFS/ascetic/vm-images/threeTierWebApp/mysql.iso_1","threeTierWebApp", "mysql", "sla-id", false); vms3.add(vm3); List<String> ids3 = new ArrayList<String>(); ids3.add("mysql-vm1"); when(vmMaClient.deployVMs(eq(vms3))).thenReturn(ids3); List<Vm> vms4 = new ArrayList<Vm>(); VmWithEquals vm4 = new VmWithEquals("JMeter_1","jmeter-uuid",1,1024,20, 0, "/DFS/ascetic/vm-images/threeTierWebApp/jmeter.iso_1","threeTierWebApp", "jmeter", "sla-id", false); vms4.add(vm4); List<String> ids4 = new ArrayList<String>(); ids4.add("jmeter-vm1"); when(vmMaClient.deployVMs(eq(vms4))).thenReturn(ids4); VMDAO vmDAO = mock(VMDAO.class); when(vmDAO.save((VM) any())).thenReturn(true); ImageDAO imageDAO = mock(ImageDAO.class); Image image1 = new Image(); image1.setOvfId("haproxy-img"); image1.setOvfHref("/DFS/ascetic/vm-images/threeTierWebApp/haproxy.img"); image1.setProviderImageId("haproxy-uuid"); image1.setDemo(false); when(imageDAO.save(eq(image1))).thenReturn(true); Image image2 = new Image(); image2.setOvfId("jboss-img"); image2.setOvfHref("/DFS/ascetic/vm-images/threeTierWebApp/jboss.img"); image2.setProviderImageId("jboss-uuid"); image2.setDemo(true); when(imageDAO.getDemoCacheImage("jboss-img", "/DFS/ascetic/vm-images/threeTierWebApp/jboss.img")).thenReturn(image2); Image image3 = new Image(); image3.setOvfId("mysql-img"); image3.setOvfHref("/DFS/ascetic/vm-images/threeTierWebApp/mysql.img"); image3.setProviderImageId("mysql-uuid"); image3.setDemo(false); when(imageDAO.save(eq(image3))).thenReturn(true); Image image4 = new Image(); image4.setOvfId("jmeter-img"); image4.setOvfHref("/DFS/ascetic/vm-images/threeTierWebApp/jmeter.img"); image4.setProviderImageId("jmeter-uuid"); image4.setDemo(true); when(imageDAO.getDemoCacheImage("jmeter-img", "/DFS/ascetic/vm-images/threeTierWebApp/jmeter.img")).thenReturn(null); when(imageDAO.save(eq(image4))).thenReturn(true); when(imageDAO.getById(0)).thenReturn(image1, image2, image3, image4); when(vmMaClient.getVM("haproxy-vm1")).thenReturn(new VmDeployed("haproxyVM", "haproxy-img", 1, 2, 3, 0, "", "", "", "10.0.0.1", "ACTIVE", new Date(), "")); when(vmMaClient.getVM("jboss-vm1")).thenReturn(new VmDeployed("jbossVM", "jboss-img", 1, 2, 3, 0, "", "", "", "10.0.0.2", "ACTIVE", new Date(), "")); when(vmMaClient.getVM("jboss-vm2")).thenReturn(new VmDeployed("jbossVM", "jboss-img", 1, 2, 3, 0, "", "", "", "10.0.0.2", "ACTIVE", new Date(), "")); when(vmMaClient.getVM("mysql-vm1")).thenReturn(new VmDeployed("mysqlVM", "mysql-img", 1, 2, 3, 0, "", "", "", "10.0.0.3", "ACTIVE", new Date(), "")); when(vmMaClient.getVM("jmeter-vm1")).thenReturn(new VmDeployed("jmeterVM", "jmeter-img", 1, 2, 3, 0, "", "", "", "10.0.0.4", "ACTIVE", new Date(), "")); Configuration.providerRegistryEndpoint = "http: PRClient prClient = mock(PRClient.class); when(prClient.getVMMClient(-1)).thenReturn(vmMaClient); EnergyModellerBean em = mock(EnergyModellerBean.class); DeploymentEventService deploymentEventService = mock(DeploymentEventService.class); DeploymentEvent deploymentEvent = new DeploymentEvent(); deploymentEvent.setDeploymentId(22); deploymentEvent.setDeploymentStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED); DeployEventHandler deploymentEventHandler = new DeployEventHandler(); deploymentEventHandler.deploymentDAO = deploymentDAO; deploymentEventHandler.deploymentEventService = deploymentEventService; deploymentEventHandler.applicationDAO = applicationDAO; deploymentEventHandler.imageDAO = imageDAO; deploymentEventHandler.prClient = prClient; deploymentEventHandler.vmDAO = vmDAO; deploymentEventHandler.em = em; deploymentEventHandler.deployDeployment(Event.wrap(deploymentEvent)); Thread.sleep(4000l); verify(imageDAO, times(1)).save(eq(image1)); verify(imageDAO, times(1)).getDemoCacheImage("jboss-img", "/DFS/ascetic/vm-images/threeTierWebApp/jboss.img"); verify(imageDAO, times(1)).save(eq(image3)); verify(imageDAO, times(1)).getDemoCacheImage("jmeter-img", "/DFS/ascetic/vm-images/threeTierWebApp/jmeter.img"); verify(imageDAO, times(1)).save(eq(image4)); verify(vmMaClient, times(1)).getVM("haproxy-vm1"); verify(vmMaClient, times(1)).getVM("jboss-vm1"); verify(vmMaClient, times(1)).getVM("jboss-vm2"); verify(vmMaClient, times(1)).getVM("mysql-vm1"); verify(vmMaClient, times(1)).getVM("jmeter-vm1"); verify(vmDAO, times(5)).save((VM) any()); ArgumentCaptor<Deployment> deploymentCaptor = ArgumentCaptor.forClass(Deployment.class); verify(deploymentDAO, times(7)).update(deploymentCaptor.capture()); assertEquals(5, deploymentCaptor.getValue().getVms().size()); assertEquals("haproxy", deploymentCaptor.getValue().getVms().get(0).getOvfId()); assertEquals("10.0.0.1", deploymentCaptor.getValue().getVms().get(0).getIp()); assertEquals("haproxy-vm1", deploymentCaptor.getValue().getVms().get(0).getProviderVmId()); assertEquals(2, deploymentCaptor.getValue().getVms().get(0).getNumberVMsMax()); assertEquals(1, deploymentCaptor.getValue().getVms().get(0).getNumberVMsMin()); assertEquals("ACTIVE", deploymentCaptor.getValue().getVms().get(0).getStatus()); assertEquals(1, deploymentCaptor.getValue().getVms().get(0).getImages().size()); assertEquals("/DFS/ascetic/vm-images/threeTierWebApp/haproxy.img", deploymentCaptor.getValue().getVms().get(0).getImages().get(0).getOvfHref()); assertEquals("haproxy-img", deploymentCaptor.getValue().getVms().get(0).getImages().get(0).getOvfId()); assertEquals("haproxy-uuid", deploymentCaptor.getValue().getVms().get(0).getImages().get(0).getProviderImageId()); assertEquals("haproxy-uuid", deploymentCaptor.getValue().getVms().get(0).getImages().get(0).getProviderImageId()); assertFalse(deploymentCaptor.getValue().getVms().get(0).getImages().get(0).isDemo()); assertEquals("jboss", deploymentCaptor.getValue().getVms().get(1).getOvfId()); assertEquals("10.0.0.2", deploymentCaptor.getValue().getVms().get(1).getIp()); assertEquals("jboss-vm1", deploymentCaptor.getValue().getVms().get(1).getProviderVmId()); assertEquals("ACTIVE", deploymentCaptor.getValue().getVms().get(1).getStatus()); assertEquals(2, deploymentCaptor.getValue().getVms().get(1).getNumberVMsMax()); assertEquals(2, deploymentCaptor.getValue().getVms().get(1).getNumberVMsMin()); assertEquals(1, deploymentCaptor.getValue().getVms().get(1).getImages().size()); assertEquals("/DFS/ascetic/vm-images/threeTierWebApp/jboss.img", deploymentCaptor.getValue().getVms().get(1).getImages().get(0).getOvfHref()); assertEquals("jboss-img", deploymentCaptor.getValue().getVms().get(1).getImages().get(0).getOvfId()); assertEquals("jboss-uuid", deploymentCaptor.getValue().getVms().get(1).getImages().get(0).getProviderImageId()); assertTrue(deploymentCaptor.getValue().getVms().get(1).getImages().get(0).isDemo()); assertEquals("jboss", deploymentCaptor.getValue().getVms().get(2).getOvfId()); assertEquals("10.0.0.2", deploymentCaptor.getValue().getVms().get(2).getIp()); assertEquals("jboss-vm2", deploymentCaptor.getValue().getVms().get(2).getProviderVmId()); assertEquals("ACTIVE", deploymentCaptor.getValue().getVms().get(2).getStatus()); assertEquals(2, deploymentCaptor.getValue().getVms().get(2).getNumberVMsMax()); assertEquals(2, deploymentCaptor.getValue().getVms().get(2).getNumberVMsMin()); assertEquals(1, deploymentCaptor.getValue().getVms().get(2).getImages().size()); assertEquals("/DFS/ascetic/vm-images/threeTierWebApp/jboss.img", deploymentCaptor.getValue().getVms().get(2).getImages().get(0).getOvfHref()); assertEquals("jboss-img", deploymentCaptor.getValue().getVms().get(2).getImages().get(0).getOvfId()); assertEquals("jboss-uuid", deploymentCaptor.getValue().getVms().get(2).getImages().get(0).getProviderImageId()); assertEquals("mysql", deploymentCaptor.getValue().getVms().get(3).getOvfId()); assertEquals("10.0.0.3", deploymentCaptor.getValue().getVms().get(3).getIp()); assertEquals("mysql-vm1", deploymentCaptor.getValue().getVms().get(3).getProviderVmId()); assertEquals("ACTIVE", deploymentCaptor.getValue().getVms().get(3).getStatus()); assertEquals(1, deploymentCaptor.getValue().getVms().get(3).getNumberVMsMax()); assertEquals(1, deploymentCaptor.getValue().getVms().get(3).getNumberVMsMin()); assertEquals(1, deploymentCaptor.getValue().getVms().get(3).getImages().size()); assertEquals(1, deploymentCaptor.getValue().getVms().get(3).getImages().size()); assertEquals("/DFS/ascetic/vm-images/threeTierWebApp/mysql.img", deploymentCaptor.getValue().getVms().get(3).getImages().get(0).getOvfHref()); assertEquals("mysql-img", deploymentCaptor.getValue().getVms().get(3).getImages().get(0).getOvfId()); assertEquals("mysql-uuid", deploymentCaptor.getValue().getVms().get(3).getImages().get(0).getProviderImageId()); assertFalse(deploymentCaptor.getValue().getVms().get(3).getImages().get(0).isDemo()); assertEquals("jmeter", deploymentCaptor.getValue().getVms().get(4).getOvfId()); assertEquals("10.0.0.4", deploymentCaptor.getValue().getVms().get(4).getIp()); assertEquals("jmeter-vm1", deploymentCaptor.getValue().getVms().get(4).getProviderVmId()); assertEquals("ACTIVE", deploymentCaptor.getValue().getVms().get(4).getStatus()); assertEquals(1, deploymentCaptor.getValue().getVms().get(4).getImages().size()); assertEquals(1, deploymentCaptor.getValue().getVms().get(4).getImages().size()); assertEquals(1, deploymentCaptor.getValue().getVms().get(4).getNumberVMsMax()); assertEquals(1, deploymentCaptor.getValue().getVms().get(4).getNumberVMsMin()); assertEquals("/DFS/ascetic/vm-images/threeTierWebApp/jmeter.img", deploymentCaptor.getValue().getVms().get(4).getImages().get(0).getOvfHref()); assertEquals("jmeter-img", deploymentCaptor.getValue().getVms().get(4).getImages().get(0).getOvfId()); assertEquals("jmeter-uuid", deploymentCaptor.getValue().getVms().get(4).getImages().get(0).getProviderImageId()); assertTrue(deploymentCaptor.getValue().getVms().get(4).getImages().get(0).isDemo()); verify(applicationDAO, times(3)).getByName("threeTierWebApp"); ArgumentCaptor<DeploymentEvent> argument = ArgumentCaptor.forClass(DeploymentEvent.class); verify(deploymentEventService).fireDeploymentEvent(argument.capture()); assertEquals(22, argument.getValue().getDeploymentId()); assertEquals(Dictionary.APPLICATION_STATUS_DEPLOYED, argument.getValue().getDeploymentStatus()); }
@Selector(value="topic.deployment.status", reactor="@rootReactor") public void deployDeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED)) { VmManagerClient vmManagerClient = prClient.getVMMClient(deploymentEvent.getProviderId()); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); if(vmManagerClient != null) { logger.info("Creating a new thread to deploy in infrastructure the deployment: " + deploymentEvent.getDeploymentId()); logger.info("Connecting to the VMM: " + vmManagerClient.getURL()); deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentDeployingMessage(deploymentEvent.getApplicationName(), deployment); try { OvfDefinition ovfDocument = OVFUtils.getOvfDefinition(deployment.getOvf()); String applicationName = OVFUtils.getApplicationName(deployment.getOvf()); VirtualSystemCollection vsc = ovfDocument.getVirtualSystemCollection(); for(int i = 0; i < vsc.getVirtualSystemArray().length; i++) { VirtualSystem virtualSystem = vsc.getVirtualSystemAtIndex(i); String ovfID = virtualSystem.getId(); logger.info(" Starting to deploy Virtual System: " + virtualSystem.getName()); VirtualHardwareSection virtualHardwareSection = virtualSystem.getVirtualHardwareSection(); String diskId = OVFUtils.getDiskId(virtualHardwareSection); String fileId = OVFUtils.getFileId(diskId, ovfDocument.getDiskSection().getDiskArray()); String urlImg = OVFUtils.getUrlImg(ovfDocument, fileId); Image image = null; if(OVFUtils.usesACacheImage(virtualSystem)) { logger.info("This virtual system uses a cache demo image"); image = imageDAO.getDemoCacheImage(fileId, urlImg); if(image == null) { logger.info("The image was not cached, we need to uplaod first"); image = ImageUploader.uploadImage(urlImg, fileId, true, applicationName, vmManagerClient, applicationDAO, imageDAO); } } else { image = ImageUploader.uploadImage(urlImg, fileId, false, applicationName, vmManagerClient, applicationDAO, imageDAO); } String ovfVirtualSystemID = virtualSystem.getId(); VMLimits vmLimits = OVFUtils.getUpperAndLowerVMlimits(virtualSystem); long minNumberVMs = vmLimits.getLowerNumberOfVMs(); long maxNumberVMs = vmLimits.getUpperNumberOfVMs(); int priceSchema = OVFUtils.getPriceSchema(virtualSystem.getProductSectionAtIndex(0)); boolean publicIP = false; try { publicIP = virtualSystem.getProductSectionAtIndex(0).isAssociatePublicIp(); } catch(NullPointerException ex) {} String vmName = virtualSystem.getName(); int cpus = virtualSystem.getVirtualHardwareSection().getNumberOfVirtualCPUs(); int ramMb = virtualSystem.getVirtualHardwareSection().getMemorySize(); String isoPath = OVFUtils.getIsoPathFromVm(virtualSystem.getVirtualHardwareSection(), ovfDocument); logger.info("ISO patth: " + isoPath); int capacity = OVFUtils.getCapacity(ovfDocument, diskId); image = imageDAO.getById(image.getId()); for(int j = 0; j < minNumberVMs; j++) { logger.info(" OVF-ID: " + ovfVirtualSystemID + " #VMs: " + minNumberVMs + " Name: " + vmName + " CPU: " + cpus + " RAM: " + ramMb + " Disk capacity: " + capacity + " ISO Path: " + isoPath + " PUBLIC IP: " + publicIP); int suffixInt = j + 1; String suffix = "_" + suffixInt; String iso = ""; if(isoPath != null) iso = isoPath + suffix ; Vm virtMachine = new Vm(vmName + suffix, image.getProviderImageId(), cpus, ramMb, capacity, 0, iso , ovfDocument.getVirtualSystemCollection().getId(), ovfID, "", publicIP ); logger.debug("virtMachine: " + virtMachine); List<Vm> vms = new ArrayList<Vm>(); vms.add(virtMachine); List<String> vmIds = vmManagerClient.deployVMs(vms); logger.debug("Id: " + vmIds.get(0)); for(String id : vmIds) { VmDeployed vmDeployed = vmManagerClient.getVM(id); VM vmToDB = new VM(); vmToDB.setIp(vmDeployed.getIpAddress()); vmToDB.setOvfId(ovfVirtualSystemID); vmToDB.setStatus(vmDeployed.getState()); vmToDB.setProviderVmId(id); vmToDB.setNumberVMsMax(maxNumberVMs); vmToDB.setNumberVMsMin(minNumberVMs); if(vmLimits.getMinNumberCPUs() > 0) { vmToDB.setCpuMin(vmLimits.getMinNumberCPUs()); } else { vmToDB.setCpuMin(cpus); } vmToDB.setCpuActual(cpus); if(vmLimits.getMaxNumberCPUs() > 0 ) { vmToDB.setCpuMax(vmLimits.getMaxNumberCPUs()); } else { vmToDB.setCpuMax(cpus); } vmToDB.setDiskMin(capacity); vmToDB.setDiskActual(capacity); vmToDB.setDiskMax(capacity); vmToDB.setRamMin(ramMb); vmToDB.setRamActual(ramMb); vmToDB.setRamMax(ramMb); vmToDB.setSwapMax(0); vmToDB.setSwapActual(0); vmToDB.setSwapMin(0); if(priceSchema != -1) { vmToDB.setPriceSchema(new Long(priceSchema)); } vmToDB.setProviderId("" + deploymentEvent.getProviderId()); vmDAO.save(vmToDB); vmToDB.addImage(image); vmDAO.update(vmToDB); deployment.addVM(vmToDB); deploymentDAO.update(deployment); AmqpProducer.sendVMDeployedMessage(applicationName, deployment, vmToDB); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYED); try { logger.info("Initializing the deployment into the PriceModeller"); PriceModellerBean.initializeDeployment(deployment); } catch(NullPointerException ex) { logger.warn("PriceModeller object does not exist!!!"); } deploymentDAO.update(deployment); } catch(OvfRuntimeException ex) { logger.info("Error parsing OVF file: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } catch (Exception ex){ logger.info("Error triying to deploy new VMs: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } deploymentEvent.setDeploymentStatus(deployment.getStatus()); AmqpProducer.sendDeploymentDeployedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } else { logger.info("Error, not available VMM Client"); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } }
DeployEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void deployDeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED)) { VmManagerClient vmManagerClient = prClient.getVMMClient(deploymentEvent.getProviderId()); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); if(vmManagerClient != null) { logger.info("Creating a new thread to deploy in infrastructure the deployment: " + deploymentEvent.getDeploymentId()); logger.info("Connecting to the VMM: " + vmManagerClient.getURL()); deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentDeployingMessage(deploymentEvent.getApplicationName(), deployment); try { OvfDefinition ovfDocument = OVFUtils.getOvfDefinition(deployment.getOvf()); String applicationName = OVFUtils.getApplicationName(deployment.getOvf()); VirtualSystemCollection vsc = ovfDocument.getVirtualSystemCollection(); for(int i = 0; i < vsc.getVirtualSystemArray().length; i++) { VirtualSystem virtualSystem = vsc.getVirtualSystemAtIndex(i); String ovfID = virtualSystem.getId(); logger.info(" Starting to deploy Virtual System: " + virtualSystem.getName()); VirtualHardwareSection virtualHardwareSection = virtualSystem.getVirtualHardwareSection(); String diskId = OVFUtils.getDiskId(virtualHardwareSection); String fileId = OVFUtils.getFileId(diskId, ovfDocument.getDiskSection().getDiskArray()); String urlImg = OVFUtils.getUrlImg(ovfDocument, fileId); Image image = null; if(OVFUtils.usesACacheImage(virtualSystem)) { logger.info("This virtual system uses a cache demo image"); image = imageDAO.getDemoCacheImage(fileId, urlImg); if(image == null) { logger.info("The image was not cached, we need to uplaod first"); image = ImageUploader.uploadImage(urlImg, fileId, true, applicationName, vmManagerClient, applicationDAO, imageDAO); } } else { image = ImageUploader.uploadImage(urlImg, fileId, false, applicationName, vmManagerClient, applicationDAO, imageDAO); } String ovfVirtualSystemID = virtualSystem.getId(); VMLimits vmLimits = OVFUtils.getUpperAndLowerVMlimits(virtualSystem); long minNumberVMs = vmLimits.getLowerNumberOfVMs(); long maxNumberVMs = vmLimits.getUpperNumberOfVMs(); int priceSchema = OVFUtils.getPriceSchema(virtualSystem.getProductSectionAtIndex(0)); boolean publicIP = false; try { publicIP = virtualSystem.getProductSectionAtIndex(0).isAssociatePublicIp(); } catch(NullPointerException ex) {} String vmName = virtualSystem.getName(); int cpus = virtualSystem.getVirtualHardwareSection().getNumberOfVirtualCPUs(); int ramMb = virtualSystem.getVirtualHardwareSection().getMemorySize(); String isoPath = OVFUtils.getIsoPathFromVm(virtualSystem.getVirtualHardwareSection(), ovfDocument); logger.info("ISO patth: " + isoPath); int capacity = OVFUtils.getCapacity(ovfDocument, diskId); image = imageDAO.getById(image.getId()); for(int j = 0; j < minNumberVMs; j++) { logger.info(" OVF-ID: " + ovfVirtualSystemID + " #VMs: " + minNumberVMs + " Name: " + vmName + " CPU: " + cpus + " RAM: " + ramMb + " Disk capacity: " + capacity + " ISO Path: " + isoPath + " PUBLIC IP: " + publicIP); int suffixInt = j + 1; String suffix = "_" + suffixInt; String iso = ""; if(isoPath != null) iso = isoPath + suffix ; Vm virtMachine = new Vm(vmName + suffix, image.getProviderImageId(), cpus, ramMb, capacity, 0, iso , ovfDocument.getVirtualSystemCollection().getId(), ovfID, "", publicIP ); logger.debug("virtMachine: " + virtMachine); List<Vm> vms = new ArrayList<Vm>(); vms.add(virtMachine); List<String> vmIds = vmManagerClient.deployVMs(vms); logger.debug("Id: " + vmIds.get(0)); for(String id : vmIds) { VmDeployed vmDeployed = vmManagerClient.getVM(id); VM vmToDB = new VM(); vmToDB.setIp(vmDeployed.getIpAddress()); vmToDB.setOvfId(ovfVirtualSystemID); vmToDB.setStatus(vmDeployed.getState()); vmToDB.setProviderVmId(id); vmToDB.setNumberVMsMax(maxNumberVMs); vmToDB.setNumberVMsMin(minNumberVMs); if(vmLimits.getMinNumberCPUs() > 0) { vmToDB.setCpuMin(vmLimits.getMinNumberCPUs()); } else { vmToDB.setCpuMin(cpus); } vmToDB.setCpuActual(cpus); if(vmLimits.getMaxNumberCPUs() > 0 ) { vmToDB.setCpuMax(vmLimits.getMaxNumberCPUs()); } else { vmToDB.setCpuMax(cpus); } vmToDB.setDiskMin(capacity); vmToDB.setDiskActual(capacity); vmToDB.setDiskMax(capacity); vmToDB.setRamMin(ramMb); vmToDB.setRamActual(ramMb); vmToDB.setRamMax(ramMb); vmToDB.setSwapMax(0); vmToDB.setSwapActual(0); vmToDB.setSwapMin(0); if(priceSchema != -1) { vmToDB.setPriceSchema(new Long(priceSchema)); } vmToDB.setProviderId("" + deploymentEvent.getProviderId()); vmDAO.save(vmToDB); vmToDB.addImage(image); vmDAO.update(vmToDB); deployment.addVM(vmToDB); deploymentDAO.update(deployment); AmqpProducer.sendVMDeployedMessage(applicationName, deployment, vmToDB); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYED); try { logger.info("Initializing the deployment into the PriceModeller"); PriceModellerBean.initializeDeployment(deployment); } catch(NullPointerException ex) { logger.warn("PriceModeller object does not exist!!!"); } deploymentDAO.update(deployment); } catch(OvfRuntimeException ex) { logger.info("Error parsing OVF file: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } catch (Exception ex){ logger.info("Error triying to deploy new VMs: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } deploymentEvent.setDeploymentStatus(deployment.getStatus()); AmqpProducer.sendDeploymentDeployedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } else { logger.info("Error, not available VMM Client"); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } } }
DeployEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void deployDeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED)) { VmManagerClient vmManagerClient = prClient.getVMMClient(deploymentEvent.getProviderId()); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); if(vmManagerClient != null) { logger.info("Creating a new thread to deploy in infrastructure the deployment: " + deploymentEvent.getDeploymentId()); logger.info("Connecting to the VMM: " + vmManagerClient.getURL()); deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentDeployingMessage(deploymentEvent.getApplicationName(), deployment); try { OvfDefinition ovfDocument = OVFUtils.getOvfDefinition(deployment.getOvf()); String applicationName = OVFUtils.getApplicationName(deployment.getOvf()); VirtualSystemCollection vsc = ovfDocument.getVirtualSystemCollection(); for(int i = 0; i < vsc.getVirtualSystemArray().length; i++) { VirtualSystem virtualSystem = vsc.getVirtualSystemAtIndex(i); String ovfID = virtualSystem.getId(); logger.info(" Starting to deploy Virtual System: " + virtualSystem.getName()); VirtualHardwareSection virtualHardwareSection = virtualSystem.getVirtualHardwareSection(); String diskId = OVFUtils.getDiskId(virtualHardwareSection); String fileId = OVFUtils.getFileId(diskId, ovfDocument.getDiskSection().getDiskArray()); String urlImg = OVFUtils.getUrlImg(ovfDocument, fileId); Image image = null; if(OVFUtils.usesACacheImage(virtualSystem)) { logger.info("This virtual system uses a cache demo image"); image = imageDAO.getDemoCacheImage(fileId, urlImg); if(image == null) { logger.info("The image was not cached, we need to uplaod first"); image = ImageUploader.uploadImage(urlImg, fileId, true, applicationName, vmManagerClient, applicationDAO, imageDAO); } } else { image = ImageUploader.uploadImage(urlImg, fileId, false, applicationName, vmManagerClient, applicationDAO, imageDAO); } String ovfVirtualSystemID = virtualSystem.getId(); VMLimits vmLimits = OVFUtils.getUpperAndLowerVMlimits(virtualSystem); long minNumberVMs = vmLimits.getLowerNumberOfVMs(); long maxNumberVMs = vmLimits.getUpperNumberOfVMs(); int priceSchema = OVFUtils.getPriceSchema(virtualSystem.getProductSectionAtIndex(0)); boolean publicIP = false; try { publicIP = virtualSystem.getProductSectionAtIndex(0).isAssociatePublicIp(); } catch(NullPointerException ex) {} String vmName = virtualSystem.getName(); int cpus = virtualSystem.getVirtualHardwareSection().getNumberOfVirtualCPUs(); int ramMb = virtualSystem.getVirtualHardwareSection().getMemorySize(); String isoPath = OVFUtils.getIsoPathFromVm(virtualSystem.getVirtualHardwareSection(), ovfDocument); logger.info("ISO patth: " + isoPath); int capacity = OVFUtils.getCapacity(ovfDocument, diskId); image = imageDAO.getById(image.getId()); for(int j = 0; j < minNumberVMs; j++) { logger.info(" OVF-ID: " + ovfVirtualSystemID + " #VMs: " + minNumberVMs + " Name: " + vmName + " CPU: " + cpus + " RAM: " + ramMb + " Disk capacity: " + capacity + " ISO Path: " + isoPath + " PUBLIC IP: " + publicIP); int suffixInt = j + 1; String suffix = "_" + suffixInt; String iso = ""; if(isoPath != null) iso = isoPath + suffix ; Vm virtMachine = new Vm(vmName + suffix, image.getProviderImageId(), cpus, ramMb, capacity, 0, iso , ovfDocument.getVirtualSystemCollection().getId(), ovfID, "", publicIP ); logger.debug("virtMachine: " + virtMachine); List<Vm> vms = new ArrayList<Vm>(); vms.add(virtMachine); List<String> vmIds = vmManagerClient.deployVMs(vms); logger.debug("Id: " + vmIds.get(0)); for(String id : vmIds) { VmDeployed vmDeployed = vmManagerClient.getVM(id); VM vmToDB = new VM(); vmToDB.setIp(vmDeployed.getIpAddress()); vmToDB.setOvfId(ovfVirtualSystemID); vmToDB.setStatus(vmDeployed.getState()); vmToDB.setProviderVmId(id); vmToDB.setNumberVMsMax(maxNumberVMs); vmToDB.setNumberVMsMin(minNumberVMs); if(vmLimits.getMinNumberCPUs() > 0) { vmToDB.setCpuMin(vmLimits.getMinNumberCPUs()); } else { vmToDB.setCpuMin(cpus); } vmToDB.setCpuActual(cpus); if(vmLimits.getMaxNumberCPUs() > 0 ) { vmToDB.setCpuMax(vmLimits.getMaxNumberCPUs()); } else { vmToDB.setCpuMax(cpus); } vmToDB.setDiskMin(capacity); vmToDB.setDiskActual(capacity); vmToDB.setDiskMax(capacity); vmToDB.setRamMin(ramMb); vmToDB.setRamActual(ramMb); vmToDB.setRamMax(ramMb); vmToDB.setSwapMax(0); vmToDB.setSwapActual(0); vmToDB.setSwapMin(0); if(priceSchema != -1) { vmToDB.setPriceSchema(new Long(priceSchema)); } vmToDB.setProviderId("" + deploymentEvent.getProviderId()); vmDAO.save(vmToDB); vmToDB.addImage(image); vmDAO.update(vmToDB); deployment.addVM(vmToDB); deploymentDAO.update(deployment); AmqpProducer.sendVMDeployedMessage(applicationName, deployment, vmToDB); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYED); try { logger.info("Initializing the deployment into the PriceModeller"); PriceModellerBean.initializeDeployment(deployment); } catch(NullPointerException ex) { logger.warn("PriceModeller object does not exist!!!"); } deploymentDAO.update(deployment); } catch(OvfRuntimeException ex) { logger.info("Error parsing OVF file: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } catch (Exception ex){ logger.info("Error triying to deploy new VMs: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } deploymentEvent.setDeploymentStatus(deployment.getStatus()); AmqpProducer.sendDeploymentDeployedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } else { logger.info("Error, not available VMM Client"); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } }  }
DeployEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void deployDeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED)) { VmManagerClient vmManagerClient = prClient.getVMMClient(deploymentEvent.getProviderId()); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); if(vmManagerClient != null) { logger.info("Creating a new thread to deploy in infrastructure the deployment: " + deploymentEvent.getDeploymentId()); logger.info("Connecting to the VMM: " + vmManagerClient.getURL()); deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentDeployingMessage(deploymentEvent.getApplicationName(), deployment); try { OvfDefinition ovfDocument = OVFUtils.getOvfDefinition(deployment.getOvf()); String applicationName = OVFUtils.getApplicationName(deployment.getOvf()); VirtualSystemCollection vsc = ovfDocument.getVirtualSystemCollection(); for(int i = 0; i < vsc.getVirtualSystemArray().length; i++) { VirtualSystem virtualSystem = vsc.getVirtualSystemAtIndex(i); String ovfID = virtualSystem.getId(); logger.info(" Starting to deploy Virtual System: " + virtualSystem.getName()); VirtualHardwareSection virtualHardwareSection = virtualSystem.getVirtualHardwareSection(); String diskId = OVFUtils.getDiskId(virtualHardwareSection); String fileId = OVFUtils.getFileId(diskId, ovfDocument.getDiskSection().getDiskArray()); String urlImg = OVFUtils.getUrlImg(ovfDocument, fileId); Image image = null; if(OVFUtils.usesACacheImage(virtualSystem)) { logger.info("This virtual system uses a cache demo image"); image = imageDAO.getDemoCacheImage(fileId, urlImg); if(image == null) { logger.info("The image was not cached, we need to uplaod first"); image = ImageUploader.uploadImage(urlImg, fileId, true, applicationName, vmManagerClient, applicationDAO, imageDAO); } } else { image = ImageUploader.uploadImage(urlImg, fileId, false, applicationName, vmManagerClient, applicationDAO, imageDAO); } String ovfVirtualSystemID = virtualSystem.getId(); VMLimits vmLimits = OVFUtils.getUpperAndLowerVMlimits(virtualSystem); long minNumberVMs = vmLimits.getLowerNumberOfVMs(); long maxNumberVMs = vmLimits.getUpperNumberOfVMs(); int priceSchema = OVFUtils.getPriceSchema(virtualSystem.getProductSectionAtIndex(0)); boolean publicIP = false; try { publicIP = virtualSystem.getProductSectionAtIndex(0).isAssociatePublicIp(); } catch(NullPointerException ex) {} String vmName = virtualSystem.getName(); int cpus = virtualSystem.getVirtualHardwareSection().getNumberOfVirtualCPUs(); int ramMb = virtualSystem.getVirtualHardwareSection().getMemorySize(); String isoPath = OVFUtils.getIsoPathFromVm(virtualSystem.getVirtualHardwareSection(), ovfDocument); logger.info("ISO patth: " + isoPath); int capacity = OVFUtils.getCapacity(ovfDocument, diskId); image = imageDAO.getById(image.getId()); for(int j = 0; j < minNumberVMs; j++) { logger.info(" OVF-ID: " + ovfVirtualSystemID + " #VMs: " + minNumberVMs + " Name: " + vmName + " CPU: " + cpus + " RAM: " + ramMb + " Disk capacity: " + capacity + " ISO Path: " + isoPath + " PUBLIC IP: " + publicIP); int suffixInt = j + 1; String suffix = "_" + suffixInt; String iso = ""; if(isoPath != null) iso = isoPath + suffix ; Vm virtMachine = new Vm(vmName + suffix, image.getProviderImageId(), cpus, ramMb, capacity, 0, iso , ovfDocument.getVirtualSystemCollection().getId(), ovfID, "", publicIP ); logger.debug("virtMachine: " + virtMachine); List<Vm> vms = new ArrayList<Vm>(); vms.add(virtMachine); List<String> vmIds = vmManagerClient.deployVMs(vms); logger.debug("Id: " + vmIds.get(0)); for(String id : vmIds) { VmDeployed vmDeployed = vmManagerClient.getVM(id); VM vmToDB = new VM(); vmToDB.setIp(vmDeployed.getIpAddress()); vmToDB.setOvfId(ovfVirtualSystemID); vmToDB.setStatus(vmDeployed.getState()); vmToDB.setProviderVmId(id); vmToDB.setNumberVMsMax(maxNumberVMs); vmToDB.setNumberVMsMin(minNumberVMs); if(vmLimits.getMinNumberCPUs() > 0) { vmToDB.setCpuMin(vmLimits.getMinNumberCPUs()); } else { vmToDB.setCpuMin(cpus); } vmToDB.setCpuActual(cpus); if(vmLimits.getMaxNumberCPUs() > 0 ) { vmToDB.setCpuMax(vmLimits.getMaxNumberCPUs()); } else { vmToDB.setCpuMax(cpus); } vmToDB.setDiskMin(capacity); vmToDB.setDiskActual(capacity); vmToDB.setDiskMax(capacity); vmToDB.setRamMin(ramMb); vmToDB.setRamActual(ramMb); vmToDB.setRamMax(ramMb); vmToDB.setSwapMax(0); vmToDB.setSwapActual(0); vmToDB.setSwapMin(0); if(priceSchema != -1) { vmToDB.setPriceSchema(new Long(priceSchema)); } vmToDB.setProviderId("" + deploymentEvent.getProviderId()); vmDAO.save(vmToDB); vmToDB.addImage(image); vmDAO.update(vmToDB); deployment.addVM(vmToDB); deploymentDAO.update(deployment); AmqpProducer.sendVMDeployedMessage(applicationName, deployment, vmToDB); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYED); try { logger.info("Initializing the deployment into the PriceModeller"); PriceModellerBean.initializeDeployment(deployment); } catch(NullPointerException ex) { logger.warn("PriceModeller object does not exist!!!"); } deploymentDAO.update(deployment); } catch(OvfRuntimeException ex) { logger.info("Error parsing OVF file: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } catch (Exception ex){ logger.info("Error triying to deploy new VMs: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } deploymentEvent.setDeploymentStatus(deployment.getStatus()); AmqpProducer.sendDeploymentDeployedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } else { logger.info("Error, not available VMM Client"); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } }  @Selector(value="topic.deployment.status", reactor="@rootReactor") void deployDeployment(Event<DeploymentEvent> event); }
DeployEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void deployDeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED)) { VmManagerClient vmManagerClient = prClient.getVMMClient(deploymentEvent.getProviderId()); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); if(vmManagerClient != null) { logger.info("Creating a new thread to deploy in infrastructure the deployment: " + deploymentEvent.getDeploymentId()); logger.info("Connecting to the VMM: " + vmManagerClient.getURL()); deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentDeployingMessage(deploymentEvent.getApplicationName(), deployment); try { OvfDefinition ovfDocument = OVFUtils.getOvfDefinition(deployment.getOvf()); String applicationName = OVFUtils.getApplicationName(deployment.getOvf()); VirtualSystemCollection vsc = ovfDocument.getVirtualSystemCollection(); for(int i = 0; i < vsc.getVirtualSystemArray().length; i++) { VirtualSystem virtualSystem = vsc.getVirtualSystemAtIndex(i); String ovfID = virtualSystem.getId(); logger.info(" Starting to deploy Virtual System: " + virtualSystem.getName()); VirtualHardwareSection virtualHardwareSection = virtualSystem.getVirtualHardwareSection(); String diskId = OVFUtils.getDiskId(virtualHardwareSection); String fileId = OVFUtils.getFileId(diskId, ovfDocument.getDiskSection().getDiskArray()); String urlImg = OVFUtils.getUrlImg(ovfDocument, fileId); Image image = null; if(OVFUtils.usesACacheImage(virtualSystem)) { logger.info("This virtual system uses a cache demo image"); image = imageDAO.getDemoCacheImage(fileId, urlImg); if(image == null) { logger.info("The image was not cached, we need to uplaod first"); image = ImageUploader.uploadImage(urlImg, fileId, true, applicationName, vmManagerClient, applicationDAO, imageDAO); } } else { image = ImageUploader.uploadImage(urlImg, fileId, false, applicationName, vmManagerClient, applicationDAO, imageDAO); } String ovfVirtualSystemID = virtualSystem.getId(); VMLimits vmLimits = OVFUtils.getUpperAndLowerVMlimits(virtualSystem); long minNumberVMs = vmLimits.getLowerNumberOfVMs(); long maxNumberVMs = vmLimits.getUpperNumberOfVMs(); int priceSchema = OVFUtils.getPriceSchema(virtualSystem.getProductSectionAtIndex(0)); boolean publicIP = false; try { publicIP = virtualSystem.getProductSectionAtIndex(0).isAssociatePublicIp(); } catch(NullPointerException ex) {} String vmName = virtualSystem.getName(); int cpus = virtualSystem.getVirtualHardwareSection().getNumberOfVirtualCPUs(); int ramMb = virtualSystem.getVirtualHardwareSection().getMemorySize(); String isoPath = OVFUtils.getIsoPathFromVm(virtualSystem.getVirtualHardwareSection(), ovfDocument); logger.info("ISO patth: " + isoPath); int capacity = OVFUtils.getCapacity(ovfDocument, diskId); image = imageDAO.getById(image.getId()); for(int j = 0; j < minNumberVMs; j++) { logger.info(" OVF-ID: " + ovfVirtualSystemID + " #VMs: " + minNumberVMs + " Name: " + vmName + " CPU: " + cpus + " RAM: " + ramMb + " Disk capacity: " + capacity + " ISO Path: " + isoPath + " PUBLIC IP: " + publicIP); int suffixInt = j + 1; String suffix = "_" + suffixInt; String iso = ""; if(isoPath != null) iso = isoPath + suffix ; Vm virtMachine = new Vm(vmName + suffix, image.getProviderImageId(), cpus, ramMb, capacity, 0, iso , ovfDocument.getVirtualSystemCollection().getId(), ovfID, "", publicIP ); logger.debug("virtMachine: " + virtMachine); List<Vm> vms = new ArrayList<Vm>(); vms.add(virtMachine); List<String> vmIds = vmManagerClient.deployVMs(vms); logger.debug("Id: " + vmIds.get(0)); for(String id : vmIds) { VmDeployed vmDeployed = vmManagerClient.getVM(id); VM vmToDB = new VM(); vmToDB.setIp(vmDeployed.getIpAddress()); vmToDB.setOvfId(ovfVirtualSystemID); vmToDB.setStatus(vmDeployed.getState()); vmToDB.setProviderVmId(id); vmToDB.setNumberVMsMax(maxNumberVMs); vmToDB.setNumberVMsMin(minNumberVMs); if(vmLimits.getMinNumberCPUs() > 0) { vmToDB.setCpuMin(vmLimits.getMinNumberCPUs()); } else { vmToDB.setCpuMin(cpus); } vmToDB.setCpuActual(cpus); if(vmLimits.getMaxNumberCPUs() > 0 ) { vmToDB.setCpuMax(vmLimits.getMaxNumberCPUs()); } else { vmToDB.setCpuMax(cpus); } vmToDB.setDiskMin(capacity); vmToDB.setDiskActual(capacity); vmToDB.setDiskMax(capacity); vmToDB.setRamMin(ramMb); vmToDB.setRamActual(ramMb); vmToDB.setRamMax(ramMb); vmToDB.setSwapMax(0); vmToDB.setSwapActual(0); vmToDB.setSwapMin(0); if(priceSchema != -1) { vmToDB.setPriceSchema(new Long(priceSchema)); } vmToDB.setProviderId("" + deploymentEvent.getProviderId()); vmDAO.save(vmToDB); vmToDB.addImage(image); vmDAO.update(vmToDB); deployment.addVM(vmToDB); deploymentDAO.update(deployment); AmqpProducer.sendVMDeployedMessage(applicationName, deployment, vmToDB); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_DEPLOYED); try { logger.info("Initializing the deployment into the PriceModeller"); PriceModellerBean.initializeDeployment(deployment); } catch(NullPointerException ex) { logger.warn("PriceModeller object does not exist!!!"); } deploymentDAO.update(deployment); } catch(OvfRuntimeException ex) { logger.info("Error parsing OVF file: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } catch (Exception ex){ logger.info("Error triying to deploy new VMs: " + ex.getMessage()); ex.printStackTrace(); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } deploymentEvent.setDeploymentStatus(deployment.getStatus()); AmqpProducer.sendDeploymentDeployedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } else { logger.info("Error, not available VMM Client"); deployment.setStatus(Dictionary.APPLICATION_STATUS_ERROR); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } }  @Selector(value="topic.deployment.status", reactor="@rootReactor") void deployDeployment(Event<DeploymentEvent> event);  }