コード例 #1
0
 public ProductRelease create(ProductRelease productRelease)
     throws InvalidEntityException, AlreadyExistsEntityException {
   log.info(
       "Create product release " + productRelease.getName() + " " + productRelease.getVersion());
   productRelease = productReleaseDao.create(productRelease);
   return productRelease;
 }
コード例 #2
0
  /**
   * 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;
  }
コード例 #3
0
  public void install(
      TierInstance tierInstance,
      ClaudiaData claudiaData,
      String envName,
      String vdc,
      ProductRelease productRelease,
      Set<Attribute> attributes,
      Task task,
      String callback)
      throws EntityNotFoundException {

    EnvironmentInstance environmentInstance = environmentInstanceManager.load(vdc, envName);

    try {
      ProductInstance productInstance =
          productInstanceManager.install(
              tierInstance, claudiaData, environmentInstance, productRelease);
      log.info(
          "Product "
              + productRelease.getProduct()
              + '-'
              + productRelease.getVersion()
              + " installed successfully");
    } catch (InvalidProductInstanceRequestException e) {
      String errorMsg = e.getMessage();
      ProductInstance instance = getInstalledProduct(productRelease, tierInstance.getVM());
      if (instance != null) {
        updateErrorTask(instance, task, errorMsg, e);
      } else {
        updateErrorTask(task, errorMsg, e);
      }
    } catch (Exception e) {
      String errorMsg =
          "The product "
              + productRelease.getProduct()
              + "-"
              + productRelease.getVersion()
              + " can not be installed in"
              + tierInstance.getVM();
      ProductInstance instance = getInstalledProduct(productRelease, tierInstance.getVM());
      if (instance != null) {
        updateErrorTask(instance, task, errorMsg, e);
      } else {
        updateErrorTask(task, errorMsg, e);
      }
    } finally {
      notifyTask(callback, task);
    }
  }
コード例 #4
0
  /**
   * 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;
  }
コード例 #5
0
  public void mergeAttributes(ProductRelease product, ProductRelease templateProduct) {

    if (product.getAttributes() != null) {
      if ((templateProduct.getAttributes() != null)
          && (!templateProduct.getAttributes().isEmpty())) {

        for (Attribute attribute : product.getAttributes()) {

          String key = attribute.getKey();
          boolean notExistInTemplate = templateProduct.getAttribute(key) == null;
          if (notExistInTemplate) {
            templateProduct.addAttribute(attribute);
          } else {
            templateProduct.getAttribute(key).setValue(attribute.getValue());
          }
        }

      } else {
        templateProduct.setAttributes(product.getAttributes());
      }
    }
  }
コード例 #6
0
  public void mergeMetadatas(ProductRelease productRelease, ProductRelease newProductRelease) {
    if (productRelease.getMetadatas() != null) {
      if (!newProductRelease.getMetadatas().isEmpty()) {

        for (Metadata metadata : productRelease.getMetadatas()) {

          String key = metadata.getKey();
          boolean notExistInTemplate = newProductRelease.getMetadata(key) == null;
          if (notExistInTemplate) {
            newProductRelease.addMetadata(metadata);
          } else {
            newProductRelease.getMetadata(key).setValue(metadata.getValue());
          }
        }

      } else {
        newProductRelease.setMetadatas(productRelease.getMetadatas());
      }
    }
  }
コード例 #7
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);
        }
      }
    }
  }
コード例 #8
0
  public ProductRelease update(ProductRelease productRelease) throws InvalidEntityException {
    log.info("Updating " + productRelease.getName());

    return productReleaseDao.update(productRelease);
  }
コード例 #9
0
  public ProductRelease loadFromSDCAndCreate(String name, ClaudiaData data)
      throws EntityNotFoundException {
    log.info("Sync product release " + name);
    ProductRelease productRelease;
    String product = name.split("-")[0];
    String version = name.split("-")[1];

    try {
      log.info("Loading from sdc " + product + " " + version);
      ProductRelease pRelease = productReleaseSdcDao.load(product, version, data);
      try {

        productRelease = productReleaseDao.load(name);

        HashSet<Attribute> attributesCopy = new HashSet<Attribute>(productRelease.getAttributes());
        HashSet<Metadata> metatadasCopy = new HashSet<Metadata>(productRelease.getMetadatas());

        productReleaseDao.removeAttributesAndMetadatas(productRelease);
        // remove
        for (Attribute attribute : attributesCopy) {
          attributeDao.remove(attribute);
        }

        for (Metadata metadata : metatadasCopy) {
          metadataDao.remove(metadata);
        }

        // add new attributes and metadatas
        for (Attribute attribute : pRelease.getAttributes()) {
          Attribute newAttribute = attributeDao.create(attribute);
          productRelease.addAttribute(newAttribute);
        }

        for (Metadata metadata : pRelease.getMetadatas()) {
          Metadata newMetadata = metadataDao.create(metadata);
          productRelease.addMetadata(newMetadata);
        }
        productReleaseDao.update(productRelease);
      } catch (Exception ex) {
        log.info("Product don't exist in database: creates");
        productRelease = create(pRelease);
      }
    } catch (EntityNotFoundException e5) {
      String msg = "Product release NOT found in SDC: " + name;
      log.warn(msg);
      throw new EntityNotFoundException(ProductRelease.class, msg, name);
    } catch (SdcException e6) {
      String msg = "Failure at loading ProductRelease from SDC" + name + " " + e6.getMessage();
      log.warn(msg);
      throw new EntityNotFoundException(ProductRelease.class, msg, name);
    } catch (InvalidEntityException e7) {
      String msg = "Failure creating new ProductRelease " + name + " " + e7.getMessage();
      log.warn(msg);
      throw new EntityNotFoundException(ProductRelease.class, msg, name);
    } catch (AlreadyExistsEntityException e8) {
      String msg = "Failure creating ProductRelease " + name + " " + e8.getMessage();
      log.warn(msg);
      throw new EntityNotFoundException(ProductRelease.class, msg, name);
    }

    return productRelease;
  }
コード例 #10
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);
    }
  }
コード例 #11
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;
  }