/**
   * 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);
  }
 private Tab createLiveDeploymentsTab() {
   Tab tab = new Tab(MSG.view_bundle_deployments());
   Criteria criteria = new Criteria();
   criteria.setAttribute("bundleVersionId", version.getId());
   tab.setPane(new BundleDeploymentListView(criteria, this.canDeploy));
   return tab;
 }
  private Tab createRecipeTab() {
    Tab tab = new Tab(MSG.view_bundle_recipe());
    DynamicForm form = new DynamicForm();

    TextAreaItem recipeCanvas = new TextAreaItem("recipe", MSG.view_bundle_recipe());
    recipeCanvas.setShowTitle(false);
    recipeCanvas.setColSpan(2);
    recipeCanvas.setWidth("100%");
    recipeCanvas.setHeight("100%");
    recipeCanvas.setValue(version.getRecipe());
    recipeCanvas.addChangeHandler(
        new ChangeHandler() {
          @Override
          public void onChange(ChangeEvent event) {
            // makes this read-only; however, since its not disabled, user can still select/copy the
            // text
            event.cancel();
          }
        });

    form.setHeight100();
    form.setWidth100();
    form.setItems(recipeCanvas);
    tab.setPane(form);
    return tab;
  }
  private TagEditorView createTagEditor() {
    boolean readOnly = !this.canTag;
    TagEditorView tagEditor =
        new TagEditorView(
            version.getTags(),
            readOnly,
            new TagsChangedCallback() {
              public void tagsChanged(HashSet<Tag> tags) {
                GWTServiceLookup.getTagService()
                    .updateBundleVersionTags(
                        version.getId(),
                        tags,
                        new AsyncCallback<Void>() {
                          public void onFailure(Throwable caught) {
                            CoreGUI.getErrorHandler()
                                .handleError(
                                    MSG.view_bundle_version_bundleVersionTagUpdateFailure(),
                                    caught);
                          }

                          public void onSuccess(Void result) {
                            CoreGUI.getMessageCenter()
                                .notify(
                                    new Message(
                                        MSG.view_bundle_version_bundleVersionTagUpdateSuccessful(),
                                        Message.Severity.Info));
                          }
                        });
              }
            });
    tagEditor.setAutoHeight();
    tagEditor.setExtraSpace(10);
    return tagEditor;
  }
  private void viewBundleVersion(BundleVersion version, ViewId nextViewId) {
    // Whenever a new view request comes in, make sure to clean house to avoid ID conflicts for
    // sub-widgets
    this.destroyMembers();

    this.version = version;

    addMember(
        new BackButton(
            MSG.view_bundle_version_backToBundle() + ": " + version.getBundle().getName(),
            LinkManager.getBundleLink(version.getBundle().getId())));

    addMember(
        new HeaderLabel(
            Canvas.getImgURL("subsystems/bundle/BundleVersion_24.png"),
            version.getName() + ": " + version.getVersion()));

    // conditionally add tags. Defaults to true, not available in JON builds.
    if (CoreGUI.isTagsEnabledForUI()) {
      addMember(createTagEditor());
    }

    addMember(createSummaryForm());

    TabSet tabs = new TabSet();
    tabs.addTab(createRecipeTab());
    tabs.addTab(createLiveDeploymentsTab());
    tabs.addTab(createFilesTab());
    addMember(tabs);

    if (nextViewId != null) {
      if (nextViewId.getPath().equals("recipe")) {
        tabs.selectTab(0);
      } else if (nextViewId.getPath().equals("deployments")) {
        tabs.selectTab(1);
      } else if (nextViewId.getPath().equals("files")) {
        tabs.selectTab(2);
      } else {
        // should we throw an exception? someone gave a bad URL; just bring them to first tab
        tabs.selectTab(0);
      }
    }

    markForRedraw();
  }
  public BundleFileUploadForm(
      String locatorId,
      BundleVersion bundleVersion,
      String name,
      boolean showNameLabel,
      Boolean isAlreadyUploaded) {

    super(locatorId, name, bundleVersion.getVersion(), showNameLabel, true, isAlreadyUploaded);
    this.bundleVersion = bundleVersion;

    setAction(GWT.getModuleBaseURL() + "BundleFileUploadServlet");
  }
  private BundleDestination getBundleDestination(
      BundleVersion bundleVersion, String destinationName, ResourceGroup group, String deployDir)
      throws Exception {
    BundleDestinationCriteria criteria = new BundleDestinationCriteria();
    criteria.addFilterBundleId(bundleVersion.getBundle().getId());
    // criteria.addFilterBundleVersionId(bundleVersion.getId());
    criteria.addFilterGroupId(group.getId());

    PageList<BundleDestination> bundleDestinations =
        bundleManager.findBundleDestinationsByCriteria(overlord, criteria);

    if (bundleDestinations.isEmpty()) {
      return bundleManager.createBundleDestination(
          overlord,
          bundleVersion.getBundle().getId(),
          destinationName,
          destinationName,
          "Root File System",
          deployDir,
          group.getId());
    }

    for (BundleDestination destination : bundleDestinations) {
      if (destination.getDeployDir().equals(deployDir)) {
        return destination;
      }
    }

    throw new RuntimeException(
        "Unable to get bundle destination for [bundleId: "
            + bundleVersion.getBundle().getId()
            + ", bunldleVersionId: "
            + bundleVersion.getId()
            + ", destination: "
            + destinationName
            + ", deployDir: "
            + deployDir
            + "]");
  }
  private DynamicForm createSummaryForm() {

    DynamicForm form = new DynamicForm();
    form.setWidth100();
    form.setColWidths("20%", "40%", "40%");
    form.setNumCols(3);
    form.setAutoHeight();
    form.setWrapItemTitles(false);
    form.setExtraSpace(10);
    form.setIsGroup(true);
    form.setGroupTitle(MSG.common_title_summary());
    form.setPadding(5);

    CanvasItem actionItem = new CanvasItem("actions");
    actionItem.setColSpan(1);
    actionItem.setRowSpan(4);
    actionItem.setShowTitle(false);
    actionItem.setCanvas(getActionLayout());

    StaticTextItem versionItem = new StaticTextItem("version", MSG.common_title_version());
    versionItem.setValue(version.getVersion());

    StaticTextItem liveDeploymentsItem =
        new StaticTextItem("deployments", MSG.view_bundle_deployments());
    liveDeploymentsItem.setValue(version.getBundleDeployments().size());

    StaticTextItem filesItems = new StaticTextItem("files", MSG.view_bundle_files());
    filesItems.setValue(version.getBundleFiles().size());

    StaticTextItem descriptionItem =
        new StaticTextItem("description", MSG.common_title_description());
    descriptionItem.setValue(version.getDescription());

    form.setFields(versionItem, actionItem, liveDeploymentsItem, filesItems, descriptionItem);
    return form;
  }
  public ControlResults invoke(String operation, Configuration params) {
    ControlResults results = new ControlResults();

    try {
      Bundle bundle = getBundle();
      BundleVersion bundleVersion = getBundleVersion(bundle);

      Configuration bundleConfig = new Configuration();
      File clusterDir = new File(params.getSimpleValue("clusterDirectory"));
      int numNodes = Integer.parseInt(params.getSimpleValue("numberOfNodes"));
      int replicationFactor = Integer.parseInt(params.getSimpleValue("replicationFactor", "1"));
      String hostname = params.getSimpleValue("host");

      Resource platform = getPlatform(hostname);
      ResourceGroup group = getPlatformGroup(platform, hostname);

      Set<String> ipAddresses = calculateLocalIPAddresses(numNodes);

      for (int i = 0; i < numNodes; ++i) {
        Set<String> seeds = getSeeds(ipAddresses, i + 1);
        int jmxPort = 7200 + i;

        Configuration deploymentConfig = new Configuration();
        deploymentConfig.put(new PropertySimple("cluster.name", "rhqdev"));
        deploymentConfig.put(new PropertySimple("cluster.dir", clusterDir.getAbsolutePath()));
        deploymentConfig.put(new PropertySimple("auto.bootstrap", "false"));
        deploymentConfig.put(new PropertySimple("data.dir", "data"));
        deploymentConfig.put(new PropertySimple("commitlog.dir", "commit_log"));
        deploymentConfig.put(new PropertySimple("log.dir", "logs"));
        deploymentConfig.put(new PropertySimple("saved.caches.dir", "saved_caches"));
        deploymentConfig.put(new PropertySimple("hostname", getLocalIPAddress(i + 1)));
        deploymentConfig.put(new PropertySimple("seeds", collectionToString(seeds)));
        deploymentConfig.put(new PropertySimple("jmx.port", Integer.toString(jmxPort)));
        deploymentConfig.put(new PropertySimple("initial.token", generateToken(i, numNodes)));
        deploymentConfig.put(new PropertySimple("install.schema", i == 0));
        deploymentConfig.put(new PropertySimple("replication.factor", replicationFactor));

        String destinationName = "cassandra-node[" + i + "]-deployment";
        String deployDir = new File(clusterDir, "node" + i).getAbsolutePath();

        BundleDestination bundleDestination =
            getBundleDestination(bundleVersion, destinationName, group, deployDir);

        BundleDeployment bundleDeployment =
            bundleManager.createBundleDeployment(
                overlord,
                bundleVersion.getId(),
                bundleDestination.getId(),
                destinationName,
                deploymentConfig);

        bundleManager.scheduleBundleDeployment(overlord, bundleDeployment.getId(), true);
      }

      return new ControlResults();
    } catch (ResourceNotFoundException e) {
      results.setError(e.getMessage());
      return results;

    } catch (Exception e) {
      results.setError(e);
      return results;
    }
  }
  private void upgrade(boolean clean) throws Exception {
    testAntBundleInitialInstall(); // install a bundle first
    cleanPluginDirs(); // clean everything but the dest dir - we want to upgrade the destination
    prepareBeforeTestMethod(); // prepare for our new test

    // deploy upgrade and test it
    ResourceType resourceType =
        new ResourceType("testSimpleBundle2Type", "plugin", ResourceCategory.SERVER, null);
    BundleType bundleType = new BundleType("testSimpleBundle2BType", resourceType);
    Repo repo = new Repo("test-bundle-two");
    PackageType packageType = new PackageType("test-bundle-two", resourceType);
    Bundle bundle = new Bundle("test-bundle-two", bundleType, repo, packageType);
    BundleVersion bundleVersion =
        new BundleVersion(
            "test-bundle-two", "3.0", bundle, getRecipeFromFile("test-bundle-three.xml"));
    BundleDestination destination =
        new BundleDestination(
            bundle,
            "testSimpleBundle2Dest",
            new ResourceGroup("testSimpleBundle2Group"),
            DEST_BASE_DIR_NAME,
            this.destDir.getAbsolutePath());

    Configuration config = new Configuration();
    String customPropName = "custom.prop";
    String customPropValue = "DEF";
    String onePropName = "one.prop";
    String onePropValue = "one-one-one";
    String threePropName = "three.prop";
    String threePropValue = "333";
    config.put(new PropertySimple(customPropName, customPropValue));
    config.put(new PropertySimple(onePropName, onePropValue));
    config.put(new PropertySimple(threePropName, threePropValue));

    BundleDeployment deployment = new BundleDeployment();
    deployment.setId(456);
    deployment.setName("test bundle 3 deployment name - upgrades test bundle 2");
    deployment.setBundleVersion(bundleVersion);
    deployment.setConfiguration(config);
    deployment.setDestination(destination);

    // copy the test archive file to the bundle files dir
    FileUtil.copyFile(
        new File("src/test/resources/test-bundle-three-archive.zip"),
        new File(this.bundleFilesDir, "test-bundle-three-archive.zip"));

    // create test.properties file in the bundle files dir
    File file1 = new File(this.bundleFilesDir, "test.properties");
    Properties props = new Properties();
    props.setProperty(customPropName, "@@" + customPropName + "@@");
    FileOutputStream outputStream = new FileOutputStream(file1);
    props.store(outputStream, "test.properties comment");
    outputStream.close();

    // create some additional files - note: recipe says to ignore "ignore/**"
    File ignoreDir = new File(this.destDir, "ignore");
    File extraDir = new File(this.destDir, "extra");
    ignoreDir.mkdirs();
    extraDir.mkdirs();
    File ignoredFile = new File(ignoreDir, "ignore-file.txt");
    File extraFile = new File(extraDir, "extra-file.txt");
    FileUtil.writeFile(new ByteArrayInputStream("ignore".getBytes()), ignoredFile);
    FileUtil.writeFile(new ByteArrayInputStream("extra".getBytes()), extraFile);

    BundleDeployRequest request = new BundleDeployRequest();
    request.setBundleFilesLocation(this.bundleFilesDir);
    request.setResourceDeployment(new BundleResourceDeployment(deployment, null));
    request.setBundleManagerProvider(new MockBundleManagerProvider());
    request.setAbsoluteDestinationDirectory(this.destDir);
    request.setCleanDeployment(clean);

    BundleDeployResult results = plugin.deployBundle(request);

    assertResultsSuccess(results);

    // test that the prop was replaced in raw file test.properties
    Properties realizedProps = new Properties();
    loadProperties(
        realizedProps, new FileInputStream(new File(this.destDir, "config/test.properties")));
    assert customPropValue.equals(realizedProps.getProperty(customPropName))
        : "didn't replace prop";

    // test that the archive was extracted properly. These are the files in the archive or removed
    // from original:
    // REMOVED: zero-file.txt
    // one/one-file.txt (content: "@@one.prop@@") <-- recipe says this is to be replaced
    // two/two-file.txt (content: "@@two.prop@@") <-- recipe does not say to replace this
    // three/three-file.txt (content: "@@three.prop@@") <-- recipe says this is to be replaced
    File zeroFile = new File(this.destDir, "zero-file.txt");
    File oneFile = new File(this.destDir, "one/one-file.txt");
    File twoFile = new File(this.destDir, "two/two-file.txt");
    File threeFile = new File(this.destDir, "three/three-file.txt");
    assert !zeroFile.exists() : "zero file should have been removed during upgrade";
    assert oneFile.exists() : "one file missing";
    assert twoFile.exists() : "two file missing";
    assert threeFile.exists() : "three file missing";
    if (clean) {
      assert !ignoredFile.exists()
          : "ignored file should have been deleted due to clean deployment request";
      assert !extraFile.exists()
          : "extra file should have been deleted due to clean deployment request";
    } else {
      assert ignoredFile.exists() : "ignored file wasn't ignored, it was deleted";
      assert !extraFile.exists() : "extra file ignored, but it should have been deleted/backed up";
    }
    assert readFile(oneFile).startsWith(onePropValue);
    assert readFile(twoFile).startsWith("@@two.prop@@");
    assert readFile(threeFile).startsWith(threePropValue);

    DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
    DeploymentProperties deploymentProps = metadata.getDeploymentProperties(deployment.getId());
    assert deploymentProps.getDeploymentId() == deployment.getId();
    assert deploymentProps.getBundleName().equals(bundle.getName());
    assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
    assert deploymentProps.getManageRootDir() == true;

    DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
    assert deploymentProps.equals(currentProps);

    // check the backup directory - note, clean flag is irrelevent when determining what should be
    // backed up
    File backupDir = metadata.getDeploymentBackupDirectory(deployment.getId());
    File extraBackupFile =
        new File(backupDir, extraDir.getName() + File.separatorChar + extraFile.getName());
    File ignoredBackupFile =
        new File(backupDir, ignoreDir.getName() + File.separatorChar + ignoredFile.getName());
    assert !ignoredBackupFile.exists() : "ignored file was backed up but it should not have been";
    assert extraBackupFile.exists() : "extra file was not backed up";
    assert "extra".equals(new String(StreamUtil.slurp(new FileInputStream(extraBackupFile))))
        : "bad backup of extra";

    DeploymentProperties previousProps = metadata.getPreviousDeploymentProperties(456);
    assert previousProps != null : "There should be previous deployment metadata";
    assert previousProps.getDeploymentId() == 123
        : "bad previous deployment metadata"; // testAntBundleInitialInstall used 123
    assert previousProps.getBundleName().equals(deploymentProps.getBundleName());
    assert previousProps
        .getBundleVersion()
        .equals("2.5"); // testAntBundleInitialInstall deployed version 2.5
    assert previousProps.getManageRootDir() == true;
  }
  /** Test deployment of an RHQ bundle recipe with archive file and raw file */
  @Test(enabled = true)
  public void testAntBundleInitialInstall() throws Exception {
    ResourceType resourceType =
        new ResourceType("testSimpleBundle2Type", "plugin", ResourceCategory.SERVER, null);
    BundleType bundleType = new BundleType("testSimpleBundle2BType", resourceType);
    Repo repo = new Repo("test-bundle-two");
    PackageType packageType = new PackageType("test-bundle-two", resourceType);
    Bundle bundle = new Bundle("test-bundle-two", bundleType, repo, packageType);
    BundleVersion bundleVersion =
        new BundleVersion(
            "test-bundle-two", "2.5", bundle, getRecipeFromFile("test-bundle-two.xml"));
    BundleDestination destination =
        new BundleDestination(
            bundle,
            "testSimpleBundle2Dest",
            new ResourceGroup("testSimpleBundle2Group"),
            DEST_BASE_DIR_NAME,
            this.destDir.getAbsolutePath());

    Configuration config = new Configuration();
    String customPropName = "custom.prop";
    String customPropValue = "ABC";
    String onePropName = "one.prop";
    String onePropValue = "111";
    config.put(new PropertySimple(customPropName, customPropValue));
    config.put(new PropertySimple(onePropName, onePropValue));

    BundleDeployment deployment = new BundleDeployment();
    deployment.setId(123);
    deployment.setName("test bundle 2 deployment name");
    deployment.setBundleVersion(bundleVersion);
    deployment.setConfiguration(config);
    deployment.setDestination(destination);

    // copy the test archive file to the bundle files dir
    FileUtil.copyFile(
        new File("src/test/resources/test-bundle-two-archive.zip"),
        new File(this.bundleFilesDir, "test-bundle-two-archive.zip"));

    // create test.properties file in the bundle files dir
    File file1 = new File(this.bundleFilesDir, "test.properties");
    Properties props = new Properties();
    props.setProperty(customPropName, "@@" + customPropName + "@@");
    FileOutputStream outputStream = new FileOutputStream(file1);
    props.store(outputStream, "test.properties comment");
    outputStream.close();

    BundleDeployRequest request = new BundleDeployRequest();
    request.setBundleFilesLocation(this.bundleFilesDir);
    request.setResourceDeployment(new BundleResourceDeployment(deployment, null));
    request.setBundleManagerProvider(new MockBundleManagerProvider());
    request.setAbsoluteDestinationDirectory(this.destDir);

    BundleDeployResult results = plugin.deployBundle(request);

    assertResultsSuccess(results);

    // test that the prop was replaced in raw file test.properties
    Properties realizedProps = new Properties();
    loadProperties(
        realizedProps, new FileInputStream(new File(this.destDir, "config/test.properties")));
    assert customPropValue.equals(realizedProps.getProperty(customPropName))
        : "didn't replace prop";

    // test that the archive was extracted properly. These are the files in the archive:
    // zero-file.txt (content: "zero")
    // one/one-file.txt (content: "@@one.prop@@") <-- recipe says this is to be replaced
    // two/two-file.txt (content: "@@two.prop@@") <-- recipe does not say to replace this
    File zeroFile = new File(this.destDir, "zero-file.txt");
    File oneFile = new File(this.destDir, "one/one-file.txt");
    File twoFile = new File(this.destDir, "two/two-file.txt");
    assert zeroFile.exists() : "zero file missing";
    assert oneFile.exists() : "one file missing";
    assert twoFile.exists() : "two file missing";
    assert readFile(zeroFile).startsWith("zero");
    assert readFile(oneFile).startsWith(onePropValue);
    assert readFile(twoFile).startsWith("@@two.prop@@");

    DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
    DeploymentProperties deploymentProps = metadata.getDeploymentProperties(deployment.getId());
    assert deploymentProps.getDeploymentId() == deployment.getId();
    assert deploymentProps.getBundleName().equals(bundle.getName());
    assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
    assert deploymentProps.getManageRootDir() == true;
    DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
    assert deploymentProps.equals(currentProps);
    DeploymentProperties previousProps =
        metadata.getPreviousDeploymentProperties(deployment.getId());
    assert previousProps == null : "There should not be any previous deployment metadata";
  }
  @Test(enabled = true)
  public void testAntBundleRevert() throws Exception {
    // install then upgrade a bundle first
    testAntBundleUpgrade();
    cleanPluginDirs(); // clean everything but the dest dir - we want to keep the metadata
    prepareBeforeTestMethod(); // prepare for our new test

    // we installed version 2.5 then upgraded to 3.0
    // now we want to revert back to 2.5
    ResourceType resourceType =
        new ResourceType("testSimpleBundle2Type", "plugin", ResourceCategory.SERVER, null);
    BundleType bundleType = new BundleType("testSimpleBundle2BType", resourceType);
    Repo repo = new Repo("test-bundle-two");
    PackageType packageType = new PackageType("test-bundle-two", resourceType);
    Bundle bundle = new Bundle("test-bundle-two", bundleType, repo, packageType);
    BundleVersion bundleVersion =
        new BundleVersion(
            "test-bundle-two", "2.5", bundle, getRecipeFromFile("test-bundle-two.xml"));
    BundleDestination destination =
        new BundleDestination(
            bundle,
            "testSimpleBundle2Dest",
            new ResourceGroup("testSimpleBundle2Group"),
            DEST_BASE_DIR_NAME,
            this.destDir.getAbsolutePath());

    Configuration config = new Configuration();
    String customPropName = "custom.prop";
    String customPropValue = "ABC-revert";
    String onePropName = "one.prop";
    String onePropValue = "111-revert";
    config.put(new PropertySimple(customPropName, customPropValue));
    config.put(new PropertySimple(onePropName, onePropValue));

    BundleDeployment deployment = new BundleDeployment();
    deployment.setId(789);
    deployment.setName("test bundle 2 deployment name - REVERT");
    deployment.setBundleVersion(bundleVersion);
    deployment.setConfiguration(config);
    deployment.setDestination(destination);

    // copy the test archive file to the bundle files dir
    FileUtil.copyFile(
        new File("src/test/resources/test-bundle-two-archive.zip"),
        new File(this.bundleFilesDir, "test-bundle-two-archive.zip"));

    // create test.properties file in the bundle files dir
    File file1 = new File(this.bundleFilesDir, "test.properties");
    Properties props = new Properties();
    props.setProperty(customPropName, "@@" + customPropName + "@@");
    FileOutputStream outputStream = new FileOutputStream(file1);
    props.store(outputStream, "test.properties comment");
    outputStream.close();

    BundleDeployRequest request = new BundleDeployRequest();
    request.setBundleFilesLocation(this.bundleFilesDir);
    request.setResourceDeployment(new BundleResourceDeployment(deployment, null));
    request.setBundleManagerProvider(new MockBundleManagerProvider());
    request.setAbsoluteDestinationDirectory(this.destDir);
    request.setRevert(true);

    BundleDeployResult results = plugin.deployBundle(request);

    assertResultsSuccess(results);

    // test that the prop was replaced in raw file test.properties
    Properties realizedProps = new Properties();
    loadProperties(
        realizedProps, new FileInputStream(new File(this.destDir, "config/test.properties")));
    assert customPropValue.equals(realizedProps.getProperty(customPropName))
        : "didn't replace prop";

    // test that the archive was extracted properly. These are the files in the archive:
    // zero-file.txt (content: "zero")
    // one/one-file.txt (content: "@@one.prop@@") <-- recipe says this is to be replaced
    // two/two-file.txt (content: "@@two.prop@@") <-- recipe does not say to replace this
    // REMOVED: three/three-file.txt <-- this existed in the upgrade, but not the original
    // ----- the following was backed up and should be reverted
    // extra/extra-file.txt

    File zeroFile = new File(this.destDir, "zero-file.txt");
    File oneFile = new File(this.destDir, "one/one-file.txt");
    File twoFile = new File(this.destDir, "two/two-file.txt");
    File threeFile = new File(this.destDir, "three/three-file.txt");
    assert zeroFile.exists() : "zero file should have been restored during revert";
    assert oneFile.exists() : "one file missing";
    assert twoFile.exists() : "two file missing";
    assert !threeFile.exists() : "three file should have been deleted during revert";

    assert readFile(zeroFile).startsWith("zero") : "bad restore of zero file";
    assert readFile(oneFile).startsWith(onePropValue);
    assert readFile(twoFile).startsWith("@@two.prop@@");

    // make sure the revert restored the backed up files
    File extraFile = new File(this.destDir, "extra/extra-file.txt");
    assert extraFile.exists()
        : "extra file should have been restored due to revert deployment request";
    assert readFile(extraFile).startsWith("extra") : "bad restore of extra file";

    DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
    DeploymentProperties deploymentProps = metadata.getDeploymentProperties(deployment.getId());
    assert deploymentProps.getDeploymentId() == deployment.getId();
    assert deploymentProps.getBundleName().equals(bundle.getName());
    assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
    assert deploymentProps.getManageRootDir() == true;

    DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
    assert deploymentProps.equals(currentProps);

    // check the backup directory - note, clean flag is irrelevent when determining what should be
    // backed up
    File backupDir = metadata.getDeploymentBackupDirectory(deployment.getId());
    File ignoredBackupFile = new File(backupDir, "ignore/ignore-file.txt");
    assert ignoredBackupFile.isFile() : "old recipe didn't ignore these, should be backed up";

    DeploymentProperties previousProps = metadata.getPreviousDeploymentProperties(789);
    assert previousProps != null : "There should be previous deployment metadata";
    assert previousProps.getDeploymentId() == 456
        : "bad previous deployment metadata"; // testAntBundleUpgrade used 456
    assert previousProps.getBundleName().equals(deploymentProps.getBundleName());
    assert previousProps
        .getBundleVersion()
        .equals("3.0"); // testAntBundleUpgrade deployed version 3.0
  }
Example #13
0
 private Tab createFilesTab() {
   Tab tab = new Tab(MSG.view_bundle_files());
   FileListView filesView = new FileListView(version.getId());
   tab.setPane(filesView);
   return tab;
 }
Example #14
0
 public List<PackageVersion> getAllBundleVersionPackageVersions(BundleVersion bundleVersion)
     throws Exception {
   int bvId = bundleVersion.getId();
   List<PackageVersion> pvs = getBundleServerService().getAllBundleVersionPackageVersions(bvId);
   return pvs;
 }