コード例 #1
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);
    }
  }
コード例 #2
0
  /**
   * 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);
    }
  }