@Override public void autoDeployBots() throws AutoDeploymentException { try { log.info("Starting auto deployment of bots..."); deploymentStore.readDeploymentInfos().stream().filter( deploymentInfo -> deploymentInfo.getDeploymentStatus() == DeploymentInfo.DeploymentStatus.deployed). forEach(deploymentInfo -> { Environment environment = Environment.valueOf(deploymentInfo.getEnvironment().toString()); String botId = deploymentInfo.getBotId(); Integer botVersion = deploymentInfo.getBotVersion(); try { botFactory.deployBot(environment, botId, botVersion, null); } catch (ServiceException | IllegalAccessException | IllegalArgumentException e) { String message = "Error while auto deploying bot (environment=%s, botId=%s, version=%s)!\n"; log.error(String.format(message, environment, botId, botVersion)); log.error(e.getLocalizedMessage(), e); } }); log.info("Finished auto deployment of bots."); } catch (IResourceStore.ResourceStoreException e) { throw new AutoDeploymentException(e.getLocalizedMessage(), e); } } }
private void deploy(final Deployment.Environment environment, final String botId, final Integer version, final Boolean autoDeploy) { Callable<Void> deployBot = () -> { try { if (EnumSet.of(Status.NOT_FOUND, Status.ERROR).contains(checkDeploymentStatus(environment, botId, version))) { botFactory.deployBot(environment, botId, version, status -> { if (status == Status.READY && autoDeploy) { deploymentStore.setDeploymentInfo(environment.toString(), botId, version, DeploymentStatus.deployed); } }); } } catch (ServiceException e) { throwError(botId, version, e, "Error while deploying bot! (botId=%s , version=%s)"); } catch (IllegalAccessException e) { throwErrorForbidden(botId, version, e); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } return null; }; SystemRuntime.getRuntime().submitCallable(deployBot, ThreadContext.getResources()); }