Пример #1
0
  public void deleteSelectedBundles() throws Exception {
    RemoteClient remoteClient;
    Subject subject;
    try {
      remoteClient = this.perspectiveClient.getRemoteClient();
      subject = this.perspectiveClient.getSubject();
    } catch (Exception e) {
      this.facesMessages.add(
          StatusMessage.Severity.FATAL, "Failed to connect to RHQ Server - cause: " + e);
      return;
    }

    // ***NOTE***: The javassist.NotFoundException stack traces that are logged by this call can be
    // ignored.
    BundleManagerRemote bundleManager = remoteClient.getBundleManagerRemote();

    int[] selectedBundleIds = new int[this.selectedBundles.size()];
    for (int i = 0, selectedBundlesSize = this.selectedBundles.size();
        i < selectedBundlesSize;
        i++) {
      Bundle selectedBundle = this.selectedBundles.get(i);
      selectedBundleIds[i] = selectedBundle.getId();
    }

    bundleManager.deleteBundles(subject, selectedBundleIds);

    // Add message to tell the user the uninventory was a success.
    String pluralizer = (this.selectedBundles.size() == 1) ? "" : "s";
    this.facesMessages.add("Deleted " + this.selectedBundles.size() + " bundle" + pluralizer + ".");

    // Reset the data model, so the current page will get refreshed to reflect the Resources we just
    // uninventoried.
    // This is essential, since we are CONVERSATION-scoped and will live on beyond this request.
    setDataModel(null);
  }
  /**
   * deploys a bundle
   *
   * @param input bundle distribution ZIP file
   * @param group to be deployed to (a BundleDestination is created on top of given group), group
   *     must be compatible and it's resources must support bundle deployment
   * @param config input configuration for bundle (for passing input-parameter values)
   * @param destinationName - name for new destination being created
   * @param baseDirName - baseDir for deployment - this must match to resourceType contained in
   *     given group
   * @param deployDir - directory to deploy to - relative path based on baseDir
   * @return bundleDeployment where deployment has finished (either failed or success)
   * @throws Exception
   */
  public BundleDeployment deployBundle(
      File input,
      ResourceGroup group,
      Configuration config,
      String destinationName,
      String baseDirName,
      String deployDir)
      throws Exception {
    BundleVersion version = createBundleVersion(input);
    BundleDestination destination =
        bundleManager.createBundleDestination(
            client.getSubject(),
            version.getBundle().getId(),
            destinationName,
            "",
            baseDirName,
            deployDir,
            group.getId());

    BundleDeployment deployment =
        bundleManager.createBundleDeployment(
            client.getSubject(), version.getId(), destination.getId(), "", config);
    deployment =
        bundleManager.scheduleBundleDeployment(client.getSubject(), deployment.getId(), false);
    return waitForBundleDeployment(deployment);
  }
 /**
  * removes bundle from server (if found)
  *
  * @param name name of bundle
  */
 public void removeBundle(String name) {
   BundleCriteria criteria = new BundleCriteria();
   criteria.addFilterName(name);
   PageList<Bundle> bundles = bundleManager.findBundlesByCriteria(client.getSubject(), criteria);
   if (!bundles.isEmpty()) {
     try {
       bundleManager.deleteBundle(client.getSubject(), bundles.get(0).getId());
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Пример #4
0
    @Override
    public PageList<Bundle> fetchPage(PageControl pageControl) {
      PerspectiveClientUIBean perspectiveClient = BundlesUIBean.this.perspectiveClient;
      BundleManagerRemote bundleManager;
      Subject subject;
      try {
        bundleManager = perspectiveClient.getRemoteClient().getBundleManagerRemote();
        subject = BundlesUIBean.this.perspectiveClient.getSubject();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }

      BundleCriteria bundleCriteria = new BundleCriteria();
      bundleCriteria.setPageControl(pageControl);
      // TODO: Implement user-specified filters.
      PageList<Bundle> bundles = bundleManager.findBundlesByCriteria(subject, bundleCriteria);
      return bundles;
    }
 /**
  * waits until given BundleDeployment is not in PENDING or IN_PROGRESS state, then returns
  * BundleDeployment instance, which is going to be either SUCCESS or FAILURE
  *
  * @param deployment
  * @return
  */
 private BundleDeployment waitForBundleDeployment(BundleDeployment deployment) {
   while (deployment.getStatus().equals(BundleDeploymentStatus.IN_PROGRESS)
       || deployment.getStatus().equals(BundleDeploymentStatus.PENDING)) {
     try {
       Thread.currentThread().join(3 * 1000);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
     BundleDeploymentCriteria criteria = new BundleDeploymentCriteria();
     criteria.addFilterId(deployment.getId());
     deployment =
         bundleManager.findBundleDeploymentsByCriteria(client.getSubject(), criteria).get(0);
   }
   return deployment;
 }
  /**
   * creates a bundleVersion on server. This is done by uploading given BundleDistributionFile (ZIP)
   * to server. Server than read's deploy.xml from ZIP file and creates appropriate Bundle in
   * version found in ZIP
   *
   * @param input BundleDistribution ZIP file
   * @return
   * @throws Exception when input file cannot be read or Server fails creating BundleVersion
   */
  private BundleVersion createBundleVersion(File input) throws Exception {
    byte[] array;
    FileInputStream is = null;
    try {
      is = new FileInputStream(input);
      int length = (int) input.length();
      array = new byte[length];
      for (int numRead = 0, offset = 0;
          ((numRead >= 0) && (offset < array.length));
          offset += numRead) {
        numRead = is.read(array, offset, array.length - offset);
      }
      is.close();
      return bundleManager.createBundleVersionViaByteArray(client.getSubject(), array);

    } catch (Exception ex) {
      if (is != null) {
        is.close();
      }
      throw ex;
    }
  }