Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
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);
    }
  }