@Test public void testWrongStateDoesNothing() throws Exception { DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); DeploymentEventService deploymentEventService = mock(DeploymentEventService.class); ContextualizationEventHandler acceptAgreementEvent = new ContextualizationEventHandler(); acceptAgreementEvent.deploymentDAO = deploymentDAO; acceptAgreementEvent.deploymentEventService = deploymentEventService; DeploymentEvent deploymentEvent = new DeploymentEvent(); deploymentEvent.setDeploymentId(22); deploymentEvent.setDeploymentStatus("1111"); acceptAgreementEvent.contextualizeImagesOfADeployment(Event.wrap(deploymentEvent)); verify(deploymentDAO, never()).getById(deploymentEvent.getDeploymentId()); verify(deploymentDAO, never()).update(any(Deployment.class)); verify(deploymentEventService, never()).fireDeploymentEvent(any(DeploymentEvent.class)); }
@Selector(value="topic.deployment.status", reactor="@rootReactor") public void contextualizeImagesOfADeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZATION)) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_CONTEXTUALIZING + " state"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizingMessage(deploymentEvent.getApplicationName(), deployment); OvfDefinition ovf = OVFUtils.getOvfDefinition(deployment.getOvf()); if (ovf != null){ try { logger.debug(" Creating the VM Client"); VmcClient vmcClient = new VmcClient(ovf); if (vmcClient.getVmcClient() != null) { logger.debug(" VM Contextualizer successfully created"); ProgressData progressData = null; deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); VirtualSystemCollection vsc = ovf.getVirtualSystemCollection(); vsc.getProductSectionAtIndex(0).setDeploymentId("" + deployment.getId()); deployment.setOvf(ovf.toString()); deploymentDAO.update(deployment); vmcClient.getVmcClient().contextualizeService(ovf); while (true) { try { logger.info("TEST: Trying to fetch progress data..."); vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.info("TEST: No ProgressException..."); break; } catch (ProgressException e) { logger.warn("TEST: Caught ProgressException due to: " + e.getMessage()); Thread.sleep(250); } } while (true) { progressData = vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.debug(" Trying to get the progress of the contextualization. Progress: " + progressData.getCurrentPercentageCompletion() + " %"); if (progressData.isError()) { logger.error(progressData.getException().getMessage(), progressData.getException()); return; } else { logger.info("TEST: contextualizeServiceCallbackObject total progress is: " + progressData.getTotalProgress()); logger.info("TEST: contextualizeServiceCallbackObject phase history of Phase with ID: " + progressData.getPhaseName(progressData .getCurrentPhaseId()) + ", % is: " + progressData.getHistory().get( progressData.getCurrentPhaseId())); } Thread.sleep(250); if (vmcClient.getVmcClient().contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .isComplete()) { logger.warn("TEST: Detected contextualization has completed!"); break; } } logger.debug("Updating the OVF from the Contextualization..."); OvfDefinition ovfContextualized = vmcClient.getVmcClient() .contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .getOvfDefinition(); logger.debug("New OVF from VMC: " + ovfContextualized.toString()); deployment.setOvf(ovfContextualized.toString()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED); deploymentEvent.setDeploymentStatus(deployment.getStatus()); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } } catch (Exception e){ logger.error("Exception ocurred. Cause: " + e.getMessage()); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } } }
ContextualizationEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void contextualizeImagesOfADeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZATION)) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_CONTEXTUALIZING + " state"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizingMessage(deploymentEvent.getApplicationName(), deployment); OvfDefinition ovf = OVFUtils.getOvfDefinition(deployment.getOvf()); if (ovf != null){ try { logger.debug(" Creating the VM Client"); VmcClient vmcClient = new VmcClient(ovf); if (vmcClient.getVmcClient() != null) { logger.debug(" VM Contextualizer successfully created"); ProgressData progressData = null; deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); VirtualSystemCollection vsc = ovf.getVirtualSystemCollection(); vsc.getProductSectionAtIndex(0).setDeploymentId("" + deployment.getId()); deployment.setOvf(ovf.toString()); deploymentDAO.update(deployment); vmcClient.getVmcClient().contextualizeService(ovf); while (true) { try { logger.info("TEST: Trying to fetch progress data..."); vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.info("TEST: No ProgressException..."); break; } catch (ProgressException e) { logger.warn("TEST: Caught ProgressException due to: " + e.getMessage()); Thread.sleep(250); } } while (true) { progressData = vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.debug(" Trying to get the progress of the contextualization. Progress: " + progressData.getCurrentPercentageCompletion() + " %"); if (progressData.isError()) { logger.error(progressData.getException().getMessage(), progressData.getException()); return; } else { logger.info("TEST: contextualizeServiceCallbackObject total progress is: " + progressData.getTotalProgress()); logger.info("TEST: contextualizeServiceCallbackObject phase history of Phase with ID: " + progressData.getPhaseName(progressData .getCurrentPhaseId()) + ", % is: " + progressData.getHistory().get( progressData.getCurrentPhaseId())); } Thread.sleep(250); if (vmcClient.getVmcClient().contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .isComplete()) { logger.warn("TEST: Detected contextualization has completed!"); break; } } logger.debug("Updating the OVF from the Contextualization..."); OvfDefinition ovfContextualized = vmcClient.getVmcClient() .contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .getOvfDefinition(); logger.debug("New OVF from VMC: " + ovfContextualized.toString()); deployment.setOvf(ovfContextualized.toString()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED); deploymentEvent.setDeploymentStatus(deployment.getStatus()); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } } catch (Exception e){ logger.error("Exception ocurred. Cause: " + e.getMessage()); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } } } }
ContextualizationEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void contextualizeImagesOfADeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZATION)) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_CONTEXTUALIZING + " state"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizingMessage(deploymentEvent.getApplicationName(), deployment); OvfDefinition ovf = OVFUtils.getOvfDefinition(deployment.getOvf()); if (ovf != null){ try { logger.debug(" Creating the VM Client"); VmcClient vmcClient = new VmcClient(ovf); if (vmcClient.getVmcClient() != null) { logger.debug(" VM Contextualizer successfully created"); ProgressData progressData = null; deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); VirtualSystemCollection vsc = ovf.getVirtualSystemCollection(); vsc.getProductSectionAtIndex(0).setDeploymentId("" + deployment.getId()); deployment.setOvf(ovf.toString()); deploymentDAO.update(deployment); vmcClient.getVmcClient().contextualizeService(ovf); while (true) { try { logger.info("TEST: Trying to fetch progress data..."); vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.info("TEST: No ProgressException..."); break; } catch (ProgressException e) { logger.warn("TEST: Caught ProgressException due to: " + e.getMessage()); Thread.sleep(250); } } while (true) { progressData = vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.debug(" Trying to get the progress of the contextualization. Progress: " + progressData.getCurrentPercentageCompletion() + " %"); if (progressData.isError()) { logger.error(progressData.getException().getMessage(), progressData.getException()); return; } else { logger.info("TEST: contextualizeServiceCallbackObject total progress is: " + progressData.getTotalProgress()); logger.info("TEST: contextualizeServiceCallbackObject phase history of Phase with ID: " + progressData.getPhaseName(progressData .getCurrentPhaseId()) + ", % is: " + progressData.getHistory().get( progressData.getCurrentPhaseId())); } Thread.sleep(250); if (vmcClient.getVmcClient().contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .isComplete()) { logger.warn("TEST: Detected contextualization has completed!"); break; } } logger.debug("Updating the OVF from the Contextualization..."); OvfDefinition ovfContextualized = vmcClient.getVmcClient() .contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .getOvfDefinition(); logger.debug("New OVF from VMC: " + ovfContextualized.toString()); deployment.setOvf(ovfContextualized.toString()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED); deploymentEvent.setDeploymentStatus(deployment.getStatus()); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } } catch (Exception e){ logger.error("Exception ocurred. Cause: " + e.getMessage()); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } } }  }
ContextualizationEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void contextualizeImagesOfADeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZATION)) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_CONTEXTUALIZING + " state"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizingMessage(deploymentEvent.getApplicationName(), deployment); OvfDefinition ovf = OVFUtils.getOvfDefinition(deployment.getOvf()); if (ovf != null){ try { logger.debug(" Creating the VM Client"); VmcClient vmcClient = new VmcClient(ovf); if (vmcClient.getVmcClient() != null) { logger.debug(" VM Contextualizer successfully created"); ProgressData progressData = null; deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); VirtualSystemCollection vsc = ovf.getVirtualSystemCollection(); vsc.getProductSectionAtIndex(0).setDeploymentId("" + deployment.getId()); deployment.setOvf(ovf.toString()); deploymentDAO.update(deployment); vmcClient.getVmcClient().contextualizeService(ovf); while (true) { try { logger.info("TEST: Trying to fetch progress data..."); vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.info("TEST: No ProgressException..."); break; } catch (ProgressException e) { logger.warn("TEST: Caught ProgressException due to: " + e.getMessage()); Thread.sleep(250); } } while (true) { progressData = vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.debug(" Trying to get the progress of the contextualization. Progress: " + progressData.getCurrentPercentageCompletion() + " %"); if (progressData.isError()) { logger.error(progressData.getException().getMessage(), progressData.getException()); return; } else { logger.info("TEST: contextualizeServiceCallbackObject total progress is: " + progressData.getTotalProgress()); logger.info("TEST: contextualizeServiceCallbackObject phase history of Phase with ID: " + progressData.getPhaseName(progressData .getCurrentPhaseId()) + ", % is: " + progressData.getHistory().get( progressData.getCurrentPhaseId())); } Thread.sleep(250); if (vmcClient.getVmcClient().contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .isComplete()) { logger.warn("TEST: Detected contextualization has completed!"); break; } } logger.debug("Updating the OVF from the Contextualization..."); OvfDefinition ovfContextualized = vmcClient.getVmcClient() .contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .getOvfDefinition(); logger.debug("New OVF from VMC: " + ovfContextualized.toString()); deployment.setOvf(ovfContextualized.toString()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED); deploymentEvent.setDeploymentStatus(deployment.getStatus()); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } } catch (Exception e){ logger.error("Exception ocurred. Cause: " + e.getMessage()); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } } }  @Selector(value="topic.deployment.status", reactor="@rootReactor") void contextualizeImagesOfADeployment(Event<DeploymentEvent> event); }
ContextualizationEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void contextualizeImagesOfADeployment(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_CONTEXTUALIZATION)) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_CONTEXTUALIZING + " state"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizingMessage(deploymentEvent.getApplicationName(), deployment); OvfDefinition ovf = OVFUtils.getOvfDefinition(deployment.getOvf()); if (ovf != null){ try { logger.debug(" Creating the VM Client"); VmcClient vmcClient = new VmcClient(ovf); if (vmcClient.getVmcClient() != null) { logger.debug(" VM Contextualizer successfully created"); ProgressData progressData = null; deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZING); VirtualSystemCollection vsc = ovf.getVirtualSystemCollection(); vsc.getProductSectionAtIndex(0).setDeploymentId("" + deployment.getId()); deployment.setOvf(ovf.toString()); deploymentDAO.update(deployment); vmcClient.getVmcClient().contextualizeService(ovf); while (true) { try { logger.info("TEST: Trying to fetch progress data..."); vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.info("TEST: No ProgressException..."); break; } catch (ProgressException e) { logger.warn("TEST: Caught ProgressException due to: " + e.getMessage()); Thread.sleep(250); } } while (true) { progressData = vmcClient.getVmcClient().contextualizeServiceCallback(ovf.getVirtualSystemCollection().getId()); logger.debug(" Trying to get the progress of the contextualization. Progress: " + progressData.getCurrentPercentageCompletion() + " %"); if (progressData.isError()) { logger.error(progressData.getException().getMessage(), progressData.getException()); return; } else { logger.info("TEST: contextualizeServiceCallbackObject total progress is: " + progressData.getTotalProgress()); logger.info("TEST: contextualizeServiceCallbackObject phase history of Phase with ID: " + progressData.getPhaseName(progressData .getCurrentPhaseId()) + ", % is: " + progressData.getHistory().get( progressData.getCurrentPhaseId())); } Thread.sleep(250); if (vmcClient.getVmcClient().contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .isComplete()) { logger.warn("TEST: Detected contextualization has completed!"); break; } } logger.debug("Updating the OVF from the Contextualization..."); OvfDefinition ovfContextualized = vmcClient.getVmcClient() .contextualizeServiceCallback( ovf.getVirtualSystemCollection().getId()) .getOvfDefinition(); logger.debug("New OVF from VMC: " + ovfContextualized.toString()); deployment.setOvf(ovfContextualized.toString()); deployment.setStatus(Dictionary.APPLICATION_STATUS_CONTEXTUALIZED); deploymentEvent.setDeploymentStatus(deployment.getStatus()); deploymentDAO.update(deployment); AmqpProducer.sendDeploymentContextualizedMessage(deploymentEvent.getApplicationName(), deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } } catch (Exception e){ logger.error("Exception ocurred. Cause: " + e.getMessage()); AmqpProducer.sendDeploymentErrorMessage(deploymentEvent.getApplicationName(), deployment); } } } }  @Selector(value="topic.deployment.status", reactor="@rootReactor") void contextualizeImagesOfADeployment(Event<DeploymentEvent> event);  }