Esempio n. 1
0
 public Tier update(Tier tier) throws InvalidEntityException {
   log.info("Update tier " + tier.getName());
   try {
     Tier newTier = tierDao.update(tier);
     return tierDao.loadComplete(newTier);
   } catch (Exception e) {
     log.error(
         "It is not possible to update the tier " + tier.getName() + " : " + e.getMessage(), e);
     throw new InvalidEntityException(
         "It is not possible to update the tier " + tier.getName() + " : " + e.getMessage());
   }
 }
  /**
   * Create the products list associate to a Tiers list.
   *
   * @param tiers Tier List
   * @return The product list associated to each Tier.
   */
  Map<String, String> createProductList(List<Tier> tiers) {
    Map<String, String> productNameList = new HashMap<String, String>();

    for (Tier tier : tiers) {
      for (ProductRelease productRelease : tier.getProductReleases()) {

        productNameList.put(productRelease.getName() + "-" + productRelease.getVersion(), "");
      }
    }

    return productNameList;
  }
Esempio n. 3
0
  private boolean isAvailableToBeDeleted(Network net) {

    List<Tier> tiers = tierDao.findAllWithNetwork(net.getNetworkName());
    if (tiers.isEmpty()) {
      log.info("The network " + net + " can be deleted");
      return true;
    } else {
      log.info(
          "The network "
              + net.getNetworkName()
              + " cannot be deleted. The following tiers are using it");
      for (Tier tier : tiers) {
        log.info(tier.getName());
      }
      return false;
    }
  }
  /**
   * Create the software dependencies for a Tier list.
   *
   * @param tiers Tier List
   * @return The list of dependencies.
   */
  List<String> createDependenciesForTiers(List<Tier> tiers) {
    List<String> dependenciesList = new ArrayList<String>();

    for (Tier tier : tiers) {
      for (ProductRelease productRelease : tier.getProductReleases()) {

        Set<Metadata> metadataList = productRelease.getMetadatas();
        for (Metadata metadata : metadataList) {
          if (metadata.getKey().startsWith("dep")) {
            dependenciesList.add(metadata.getValue());
          }
        }
      }
    }

    return dependenciesList;
  }
Esempio n. 5
0
  public void createNetworks(Tier tier)
      throws EntityNotFoundException, InvalidEntityException, AlreadyExistsEntityException {
    List<Network> networkToBeDeployed = new ArrayList<Network>();
    for (Network network : tier.getNetworks()) {
      networkToBeDeployed.add(network);
    }

    for (Network network : networkToBeDeployed) {
      if (networkManager.exists(network.getNetworkName(), network.getVdc(), tier.getRegion())) {
        log.info("the network " + network.getNetworkName() + " already exists");
        network = networkManager.load(network.getNetworkName(), network.getVdc(), tier.getRegion());

      } else {
        network = networkManager.create(network);
      }
      tier.addNetwork(network);
    }
  }
Esempio n. 6
0
  private void existProductOrSyncWithSDC(ClaudiaData data, Tier tier)
      throws InvalidEntityException {

    if (tier.getProductReleases() != null && tier.getProductReleases().size() != 0) {
      for (ProductRelease prod : tier.getProductReleases()) {
        try {
          log.info("Sync product release " + prod.getProduct() + "-" + prod.getVersion());
          prod =
              productReleaseManager.loadFromSDCAndCreate(
                  prod.getProduct() + "-" + prod.getVersion(), data);
        } catch (Exception e2) {
          String errorMessage =
              "The ProductRelease Object "
                  + prod.getProduct()
                  + "-"
                  + prod.getVersion()
                  + " not exist in database";
          log.error(errorMessage);
          throw new InvalidEntityException(e2);
        }
      }
    }
  }
Esempio n. 7
0
  /**
   * It creates a tier.
   *
   * @throws EntityNotFoundException
   * @throws AlreadyExistsEntityException
   */
  public Tier create(ClaudiaData claudiaData, String envName, Tier tier)
      throws InvalidEntityException, InfrastructureException, EntityNotFoundException,
          AlreadyExistsEntityException {
    log.info(
        "Create tier name "
            + tier.getName()
            + " image "
            + tier.getImage()
            + " flavour "
            + tier.getFlavour()
            + " initial_number_instances "
            + tier.getInitialNumberInstances()
            + " maximum_number_instances "
            + tier.getMaximumNumberInstances()
            + " minimum_number_instances "
            + tier.getMinimumNumberInstances()
            + " floatingIp "
            + tier.getFloatingip()
            + " keyPair "
            + tier.getKeypair()
            + " icon "
            + tier.getIcono()
            + " product releases "
            + tier.getProductReleases()
            + "  vdc "
            + claudiaData.getVdc()
            + " networks "
            + tier.getNetworks());

    if (exists(tier.getName(), tier.getVdc(), envName)) {
      return load(tier.getName(), claudiaData.getVdc(), envName);
    } else {

      // check if exist product or need sync with SDC
      existProductOrSyncWithSDC(claudiaData, tier);

      // createSecurityGroups(claudiaData, tier);

      createNetworks(tier);

      return tierInsertBD(tier, claudiaData);
    }
  }
Esempio n. 8
0
  public void updateTier(ClaudiaData data, Tier tierold, Tier tiernew)
      throws InvalidEntityException, EntityNotFoundException, AlreadyExistsEntityException {

    tierold.setFlavour(tiernew.getFlavour());
    tierold.setFloatingip(tiernew.getFloatingip());
    tierold.setIcono(tiernew.getIcono());
    tierold.setImage(tiernew.getImage());
    tierold.setInitialNumberInstances(tiernew.getInitialNumberInstances());
    tierold.setKeypair(tiernew.getKeypair());
    tierold.setMaximumNumberInstances(tiernew.getMaximumNumberInstances());
    tierold.setMinimumNumberInstances(tiernew.getMinimumNumberInstances());
    tierold.setRegion(tiernew.getRegion());

    update(tierold);

    // Get networks to be delete
    Set<Network> nets = new HashSet<Network>();
    for (Network net : tierold.getNetworks()) {
      nets.add(net);
    }

    // delete networks
    tierold.setNetworks(null);
    update(tierold);

    // adding networks
    for (Network net : tiernew.getNetworks()) {
      log.info("Creating new network " + net.getNetworkName());
      try {
        net = networkManager.create(net);
      } catch (AlreadyExistsEntityException e) {
        net = networkManager.load(net.getNetworkName(), net.getVdc(), net.getRegion());
      }
      tierold.addNetwork(net);
      update(tierold);
    }

    for (Network net : nets) {
      if (isAvailableToBeDeleted(net)) {
        networkManager.delete(net);
      }
    }

    tierold.setProductReleases(null);
    update(tierold);

    if (tiernew.getProductReleases() == null) return;

    for (ProductRelease productRelease : tiernew.getProductReleases()) {
      try {
        productRelease =
            productReleaseManager.load(
                productRelease.getProduct() + "-" + productRelease.getVersion(), data);
      } catch (EntityNotFoundException e) {
        log.error(
            "The new software "
                + productRelease.getProduct()
                + "-"
                + productRelease.getVersion()
                + " is not found");
      }
      tierold.addProductRelease(productRelease);
      update(tierold);
    }
  }
Esempio n. 9
0
  /**
   * It insert the tier in the database.
   *
   * @param tier
   * @param data
   * @return
   * @throws InvalidEntityException
   * @throws InfrastructureException
   */
  public Tier tierInsertBD(Tier tier, ClaudiaData data)
      throws InvalidEntityException, InfrastructureException {
    List<Network> networskout = new ArrayList();
    try {
      return load(tier.getName(), tier.getVdc(), tier.getEnviromentName());
    } catch (EntityNotFoundException e) {

      // tier.setVdc(data.getVdc());
      // tier.setEnviromentName(data.getService());

      List<ProductRelease> productReleases = new ArrayList();
      if (tier.getProductReleases() != null && tier.getProductReleases().size() != 0) {
        for (ProductRelease p : tier.getProductReleases()) {
          productReleases.add(p);
        }
      } else {

        log.warn("There is not any product release associated to the tier " + tier.getName());
      }

      for (Network p : tier.getNetworks()) {
        networskout.add(p);
      }

      try {
        tier.setProductReleases(null);
        tier.setNetworks(null);
        tier = tierDao.create(tier);
      } catch (Exception e2) {
        String errorMessage =
            "The Tier  " + tier.getName() + "  cannot be created " + e2.getMessage();
        log.error(errorMessage);
        // restore(data, tier);
        throw new InvalidEntityException(errorMessage);
      }

      if (productReleases.size() != 0) {
        for (ProductRelease product : productReleases) {

          try {
            ProductRelease templateProduct =
                productReleaseManager.load(product.getProduct() + "-" + product.getVersion(), data);
            log.info(
                "Adding product release "
                    + templateProduct.getProduct()
                    + "-"
                    + templateProduct.getVersion()
                    + " to tier "
                    + templateProduct.getName());

            mergeAttributes(product, templateProduct);
            mergeMetadatas(product, templateProduct);

            tier.addProductRelease(templateProduct);

            tier = update(tier);
          } catch (Exception e2) {
            String errorMessage =
                "The ProductRelease Object "
                    + product.getProduct()
                    + "-"
                    + product.getVersion()
                    + " is "
                    + "NOT present in Database";
            log.error(errorMessage);
            throw new InvalidEntityException(e2);
          }
        }
      }
    }

    for (Network net : networskout) {

      try {
        net = networkManager.load(net.getNetworkName(), net.getVdc(), net.getRegion());
        log.info("Adding network " + net.getNetworkName() + "-" + " to tier " + tier.getName());
        tier.addNetwork(net);
        update(tier);
      } catch (Exception e2) {
        String errorMessage =
            "The Network Object " + net.getNetworkName() + " is " + "NOT present in Database";
        log.error(errorMessage);
        throw new InvalidEntityException(e2);
      }
    }

    return tier;
  }
Esempio n. 10
0
  /**
   * It deletes the tier.
   *
   * @param claudiaData
   * @param tier
   */
  public void delete(ClaudiaData claudiaData, Tier tier)
      throws EntityNotFoundException, InvalidEntityException, InfrastructureException {

    try {
      tier = loadTierWithNetworks(tier.getName(), tier.getVdc(), tier.getEnviromentName());
      log.info(
          "Deleting tier "
              + tier.getName()
              + " from vdc "
              + tier.getVdc()
              + "  env  "
              + tier.getEnviromentName()
              + " "
              + tier.getNetworks());
    } catch (EntityNotFoundException e) {

      String mens =
          "It is not possible to delete the tier " + tier.getName() + " since it is not exist";
      log.error(mens);
      throw new com.telefonica.euro_iaas.commons.dao.EntityNotFoundException(
          Tier.class, mens, tier);
    }

    log.info("Deleting the networks " + tier.getNetworks());

    List<Network> netsAux = new ArrayList<Network>();
    for (Network netNet : tier.getNetworks()) {
      netsAux.add(netNet);
    }

    tier.setNetworks(null);
    tierDao.update(tier);

    for (Network net : netsAux) {

      if (isAvailableToBeDeleted(net)) {
        log.info("Deleting network " + net.getNetworkName());
        try {
          networkManager.delete(net);
        } catch (Exception e) {
          log.info("There is an error to delete the network");
        }
      }
    }
    log.info("Networks deleted");

    try {
      tierDao.remove(tier);
    } catch (Exception e) {
      String mens = "It is not possible to delete the tier since it is not exist " + e.getMessage();
      log.error(mens);
      throw new InvalidEntityException(tier, e);
    }
  }
  public EnvironmentInstance createInfrasctuctureEnvironmentInstance(
      EnvironmentInstance environmentInstance, Set<Tier> tiers, ClaudiaData claudiaData)
      throws InfrastructureException, InvalidEntityException, EntityNotFoundException,
          AlreadyExistsEntityException {

    // Deploy MVs
    log.info(
        "Creating infrastructure for environment instance "
            + environmentInstance.getBlueprintName());

    for (Tier tier : tiers) {
      for (int numReplica = 1; numReplica <= tier.getInitialNumberInstances(); numReplica++) {
        // claudiaData.setVm(tier.getName());
        log.info("Deploying tier instance for tier " + tier.getName() + " " + tier.getRegion());
        Tier tierDB =
            tierManager.loadTierWithProductReleaseAndMetadata(
                tier.getName(), tier.getEnviromentName(), tier.getVdc());

        TierInstance tierInstance = new TierInstance();
        String name =
            generateVMName(
                environmentInstance.getBlueprintName(),
                tier.getName(),
                numReplica,
                claudiaData.getVdc());

        tierInstance.setName(name);
        tierInstance.setNumberReplica(numReplica);
        tierInstance.setVdc(claudiaData.getVdc());
        tierInstance.setStatus(Status.DEPLOYING);
        tierInstance.setTier(tierDB);
        VM vm = new VM();
        String fqn =
            claudiaData.getOrg().replace("_", ".")
                + ".customers."
                + claudiaData.getVdc()
                + ".services."
                + claudiaData.getService()
                + ".vees."
                + tier.getName()
                + ".replicas."
                + numReplica;

        String hostname =
            generateVMName(
                    claudiaData.getService(), tier.getName(), numReplica, claudiaData.getVdc())
                .toLowerCase();
        log.info("fqn " + fqn + " hostname " + hostname);
        vm.setFqn(fqn);
        vm.setHostname(hostname);
        tierInstance.setVM(vm);

        log.info("Deploy networks if required");

        log.info("Deploying tier instance for tier " + tier.getName() + " " + tier.getRegion());
        this.deployNetworks(claudiaData, tierInstance);
        log.info(
            "Number of networks "
                + tierInstance.getNetworkInstances().size()
                + " floatin ip "
                + tierInstance.getTier().getFloatingip());

        log.info("Inserting in database ");
        tierInstance =
            insertTierInstanceBD(
                claudiaData, environmentInstance.getEnvironment().getName(), tierInstance);
        log.info(
            "Return: Number of networks "
                + tierInstance.getNetworkInstances().size()
                + " floating ip "
                + tierInstance.getTier().getFloatingip());
        environmentInstance.addTierInstance(tierInstance);
        environmentInstanceDao.update(environmentInstance);

        try {
          tierInstanceManager.update(
              claudiaData, environmentInstance.getEnvironment().getName(), tierInstance);
        } catch (Exception e) {
          log.error("Error deploying a VM: " + e.getMessage());
          environmentInstance.setStatus(Status.ERROR);
          throw new InfrastructureException(e.getMessage());
        }

        log.info(
            "Tier instance name "
                + environmentInstance.getBlueprintName()
                + "-"
                + tier.getName()
                + "-"
                + numReplica);
        deployVM(claudiaData, tierInstance, numReplica, vm);

        tierInstance.setVM(vm);

        try {
          log.info("Inserting in database ");
          // tierInstance = insertTierInstanceBD(tierInstance);
          tierInstance.setStatus(Status.DEPLOYED);
          tierInstanceManager.update(
              claudiaData, environmentInstance.getEnvironment().getName(), tierInstance);
        } catch (EntityNotFoundException e) {
          log.info(
              "Entitiy NOt found: Tier " + tierInstance.getTier().getName() + " " + e.getMessage());
          throw new InfrastructureException(e);
        } catch (InvalidEntityException e) {
          throw new InfrastructureException(e);
        } catch (AlreadyExistsEntityException e) {
          throw new InfrastructureException(e);
        } catch (Exception e) {
          throw new InfrastructureException(e);
        }
      }
    }
    return environmentInstance;
  }
  /**
   * It deploys the required networks.
   *
   * @param data
   * @param tierInstance
   * @throws InvalidEntityException
   * @throws InfrastructureException
   * @throws EntityNotFoundException
   */
  public void deployNetworks(ClaudiaData data, TierInstance tierInstance)
      throws InvalidEntityException, InfrastructureException, EntityNotFoundException,
          AlreadyExistsEntityException {
    Tier tier = tierInstance.getTier();
    tier =
        tierManager.loadTierWithNetworks(tier.getName(), data.getVdc(), tier.getEnviromentName());
    // Creating networks...
    log.info(
        "Deploying network for tier instance "
            + tierInstance.getName()
            + " "
            + tier.getNetworks().size()
            + " region "
            + tier.getRegion());
    List<Network> networkToBeDeployed = new ArrayList<Network>();
    for (Network network : tier.getNetworks()) {
      log.info("Network to be added " + network.getNetworkName());
      if (network.getNetworkName().equals("Internet")) {

        tier.setFloatingip("true");
        tier = tierManager.update(tier);
        tierInstance.update(tier);
      } else {
        networkToBeDeployed.add(network);
      }
    }

    for (Network network : networkToBeDeployed) {
      log.info(
          "Network instance to be deployed: "
              + network.getNetworkName()
              + " vdc "
              + data.getVdc()
              + " "
              + network.getRegion()
              + " and federated "
              + network.getfederatedNetwork());
      network = networkManager.load(network.getNetworkName(), data.getVdc(), network.getRegion());
      NetworkInstance networkInst = network.toNetworkInstance();
      log.info(
          "Network instance to be deployed: "
              + network.getNetworkName()
              + " vdc "
              + data.getVdc()
              + " region "
              + networkInst.getRegionName()
              + " and networkInst "
              + network.getfederatedNetwork());

      if (networkInstanceManager.exists(data, networkInst, tier.getRegion())) {
        log.info("the network inst " + networkInst.getNetworkName() + " already exists");
        networkInst =
            networkInstanceManager.load(networkInst.getNetworkName(), data, tier.getRegion());
      } else {
        try {
          log.info("the network inst " + networkInst.getNetworkName() + " do not exists");
          networkInst =
              networkInstanceManager.create(data, networkInst, tierInstance.getTier().getRegion());
        } catch (AlreadyExistsEntityException e2) {
          throw new InvalidEntityException(network);
        } catch (InfrastructureException e) {
          String mens =
              "Error to deploy a network " + network.getNetworkName() + " :" + e.getMessage();
          throw new InfrastructureException(mens);
        }
      }
      log.info("Adding network to tier isntance " + networkInst.getNetworkName());
      tierInstance.addNetworkInstance(networkInst);
    }
  }