private ProductInstance getInstalledProduct(ProductRelease productRelease, VM vm) {
   ProductInstanceSearchCriteria criteria = new ProductInstanceSearchCriteria();
   // criteria.setVm(vm);
   criteria.setProductRelease(productRelease);
   try {
     return productInstanceManager.loadByCriteria(criteria);
   } catch (EntityNotFoundException e) {
     return null;
   } catch (NotUniqueResultException e) {
     return null;
   }
 }
  public void uninstall(
      ClaudiaData data, ProductInstance productInstance, Task task, String callback) {

    try {
      productInstanceManager.uninstall(data, productInstance);
      updateSuccessTask(task, productInstance);
      log.info(
          "Product Release "
              + productInstance.getProductRelease().getProduct()
              + "-"
              + productInstance.getProductRelease().getVersion()
              + " uninstalled successfully");
    } catch (ProductInstallatorException e) {
      String errorMsg = "Error Unistalling ProductInstance " + e.getMessage();
      log.info(errorMsg);

    } catch (Exception e) {
      String errorMsg =
          "The product "
              + productInstance.getProductRelease().getProduct()
              + "-"
              + productInstance.getProductRelease().getVersion()
              + " can not be uninstalled";
    } finally {
      notifyTask(callback, task);
    }

    /*
     * try { productInstanceManager.uninstall(productInstance);
     * updateSuccessTask(task, productInstance); log.info("Product " +
     * productInstance.getProduct().getProduct().getName() + "-" +
     * productInstance.getProduct().getVersion() +
     * " uninstalled successfully"); } catch (FSMViolationException e) {
     * updateErrorTask(productInstance, task, "The product " +
     * productInstance.getId() +
     * " can not be uninstalled due to previous status", e); } catch
     * (ApplicationInstalledException e) { updateErrorTask(productInstance,
     * task, "The product " + productInstance.getId() +
     * " can not be uninstalled due to some applications are" +
     * " installed on it.", e); } catch (NodeExecutionException e) {
     * updateErrorTask(productInstance, task, "The product " +
     * productInstance.getId() +
     * " can not be uninstalled due to an error executing in node.", e); }
     * catch (Throwable e) { updateErrorTask(productInstance, task,
     * "The product " + productInstance.getId() +
     * " can not be uninstalled due to unexpected error.", e); } finally {
     * notifyTask(callback, task); }
     */

  }
  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);
    }
  }
 public ProductInstance load(String vdc, String name) throws EntityNotFoundException {
   return productInstanceManager.load(vdc, name);
 }