@Override
  @Transactional
  public void addNewAlias(Application application, String alias)
      throws ServiceException, CheckException {

    logger.info("ALIAS VALUE IN addNewAlias : " + alias);

    if (checkAliasIfExists(alias)) {
      throw new CheckException(
          "This alias is already used by another application on this CloudUnit instance");
    }

    alias = alias.toLowerCase();
    if (alias.startsWith("https://") || alias.startsWith("http://") || alias.startsWith("ftp://")) {
      alias = alias.substring(alias.lastIndexOf("//") + 2, alias.length());
    }

    if (!StringUtils.isAlphanumeric(alias)) {
      throw new CheckException(
          "This alias must be alphanumeric. Please remove all other characters");
    }

    try {
      Server server = application.getServers().get(0);
      application.getAliases().add(alias);
      hipacheRedisUtils.writeNewAlias(alias, application, server.getServerAction().getServerPort());
      applicationDAO.save(application);

    } catch (DataAccessException e) {
      throw new ServiceException(e.getLocalizedMessage(), e);
    }
  }
  @Override
  @Transactional
  public void updateAliases(Application application) throws ServiceException {
    try {
      Server server = application.getServers().get(0);
      List<String> aliases = applicationDAO.findAllAliases(application.getName());
      for (String alias : aliases) {
        hipacheRedisUtils.updateAlias(alias, application, server.getServerAction().getServerPort());
      }

    } catch (DataAccessException e) {
      throw new ServiceException(e.getLocalizedMessage(), e);
    }
  }
 @Override
 @Transactional
 public void removeAlias(Application application, String alias)
     throws ServiceException, CheckException {
   try {
     hipacheRedisUtils.removeAlias(alias);
     boolean removed = application.getAliases().remove(alias);
     if (!removed) {
       throw new CheckException("Alias [" + alias + "] doesn't exist");
     }
     application = applicationDAO.save(application);
   } catch (DataAccessException e) {
     throw new ServiceException(e.getLocalizedMessage(), e);
   }
 }
  /**
   * Remove an application
   *
   * @param application
   * @param user
   * @return
   * @throws ServiceException
   */
  @Override
  @Transactional
  public Application remove(Application application, User user)
      throws ServiceException, CheckException {

    try {
      logger.info("Starting removing application " + application.getName());

      // Delete all modules
      List<Module> listModules = application.getModules();
      for (Module module : listModules) {
        try {
          moduleService.remove(application, user, module, false, application.getStatus());
        } catch (ServiceException | CheckException e) {
          application.setStatus(Status.FAIL);
          logger.error(
              "ApplicationService Error : failed to remove module "
                  + module.getName()
                  + " for application "
                  + application.getName()
                  + " : "
                  + e);
          e.printStackTrace();
        }
      }

      // Delete all alias
      List<String> aliases = new ArrayList<>();
      aliases.addAll(application.getAliases());
      for (String alias : aliases) {
        removeAlias(application, alias);
      }

      // Delete all servers
      List<Server> listServers = application.getServers();
      for (Server server : listServers) {
        serverService.remove(server.getName());
        if (listServers.indexOf(server) == listServers.size() - 1) {
          hipacheRedisUtils.removeRedisAppKey(application);
          applicationDAO.delete(server.getApplication());
          portUtils.releaseProxyPorts(application);
        }
      }

      logger.info("ApplicationService : Application successfully removed ");

    } catch (PersistenceException e) {
      setStatus(application, Status.FAIL);
      logger.error(
          "ApplicationService Error : failed to remove " + application.getName() + " : " + e);

      throw new ServiceException(e.getLocalizedMessage(), e);
    } catch (ServiceException e) {
      setStatus(application, Status.FAIL);
      logger.error(
          "ApplicationService Error : failed to remove application "
              + application.getName()
              + " : "
              + e);
    }
    return application;
  }