DeployDAO { public void initDeploy(Long deployId) { Session session = sessionFactory.openSession(); try { session.beginTransaction(); DeployStatus runningDeployStatus = new DeployStatus(); runningDeployStatus.setDeployStatusId((short) 2); DeployStatus successDeployStatus = new DeployStatus(); successDeployStatus.setDeployStatusId((short) 3); DeployStatus failDeployStatus = new DeployStatus(); failDeployStatus.setDeployStatusId((short) 4); DeployStatus pickedDeployStatus = new DeployStatus(); pickedDeployStatus.setDeployStatusId((short) 5); Criteria checkDeploymentId = session.createCriteria(ProcessDeploymentQueue.class).add(Restrictions.eq(DEPLOYMENTID, deployId)); Integer deploymentIdCount = checkDeploymentId.list().size(); LOGGER.info("Deployment Id count :" + deploymentIdCount); Criteria checkDeployingProcess = session.createCriteria(ProcessDeploymentQueue.class).add(Restrictions.and(Restrictions.eq(DEPLOYMENTID, deployId), Restrictions.eq(DEPLOYSTATUS, runningDeployStatus))); Integer deployingProcessCount = checkDeployingProcess.list().size(); LOGGER.info("Deploying process count of running deployment process:" + deployingProcessCount); Criteria checkDeployedProcess = session.createCriteria(ProcessDeploymentQueue.class).add(Restrictions.eq(DEPLOYMENTID, deployId)).add(Restrictions.or(Restrictions.eq(DEPLOYSTATUS, failDeployStatus), Restrictions.eq(DEPLOYSTATUS, successDeployStatus))); Integer deployedProcessCount = checkDeployedProcess.list().size(); LOGGER.info("Deployed process count of deployed process :" + deployedProcessCount); List<ProcessDeploymentQueue> processDeploymentQueueList = new ArrayList<ProcessDeploymentQueue>(); Criteria checkPickedProcesses = session.createCriteria(ProcessDeploymentQueue.class).add(Restrictions.and(Restrictions.eq(DEPLOYMENTID, deployId), Restrictions.eq(DEPLOYSTATUS, pickedDeployStatus))); processDeploymentQueueList = checkPickedProcesses.list(); Integer pickedCount = checkPickedProcesses.list().size(); LOGGER.info("Picked process count :" + pickedCount); if (deploymentIdCount == 0) { throw new MetadataException("The deployment Id is not present: " + deployId); } else if (deployingProcessCount != 0) { throw new MetadataException("The process is already deploying:" + deployId); } else if (deployedProcessCount != 0) { throw new MetadataException("The process is already deployed: " + deployId); } else { if (pickedCount == 0) { LOGGER.info("The process is not yet picked for deployment"); } else { java.util.Date date = new java.util.Date(); processDeploymentQueueList.get(0).setStartTs(new Timestamp(date.getTime())); processDeploymentQueueList.get(0).setDeployStatus(runningDeployStatus); session.update(processDeploymentQueueList.get(0)); } session.getTransaction().commit(); } } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error("Error occurred ", e); } finally { session.close(); } }  void initDeploy(Long deployId); void termDeploy(Long deployId); void haltDeploy(Long deployId);  }
@Test public void testInitDeploy() throws Exception { BusDomain busDomain = busDomainDAO.get(1); ProcessType processType = processTypeDAO.get(2); Process process = new Process(); process.setProcessName("Test"); process.setDescription("Test Process"); process.setBusDomain(busDomain); process.setProcessType(processType); process.setAddTs(new Date()); process.setCanRecover(true); process.setEnqueuingProcessId("0"); process.setNextProcessId("10802"); process.setDeleteFlag(false); process.setEditTs(new Date()); Integer id = processDAO.insert(process); DeployStatus deployStatus = deployStatusDAO.get((short) 1); ProcessDeploymentQueue processDeploymentQueue = new ProcessDeploymentQueue(); processDeploymentQueue.setProcess(process); processDeploymentQueue.setBusDomain(busDomain); processDeploymentQueue.setDeployStatus(deployStatus); processDeploymentQueue.setInsertTs(new Date()); processDeploymentQueue.setProcessType(processType); processDeploymentQueue.setUserName("Test"); Long processDeploymentQueueId = processDeploymentQueueDAO.insert(processDeploymentQueue); deployDAO.initDeploy(processDeploymentQueueId); LOGGER.info("The init deploy test executed "); processDeploymentQueueDAO.delete(processDeploymentQueueId); processDAO.testDelete(id); }