/**
   * 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);
  }
  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;
    }
  }