/** * 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 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 + "]"); }
// Redeploy to existing destination public BundleDeployWizard(BundleDestination destination) { if (null == destination) { throw new IllegalArgumentException("destination is null"); } this.setInitialDeployment(false); this.setBundleId(destination.getBundle().getId()); this.setDestination(destination); List<WizardStep> steps = init(); steps.add(new SelectBundleVersionStep(this)); steps.add(new GetDeploymentConfigStep(this)); steps.add(new GetDeploymentInfoStep(this)); steps.add(new DeployStep(this)); }
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; } }
/** * Given a deployment, this examines the destination and the resource to determine where exactly * the bundle distribution should be written. * * @param bundleResourceDeployment describes where the bundle should be or is deployed * @return absolute directory location where the bundle should be deployed */ private File getAbsoluteDestinationDir(BundleResourceDeployment bundleResourceDeployment) { BundleDestination dest = bundleResourceDeployment.getBundleDeployment().getDestination(); String destBaseDirName = dest.getDestinationBaseDirectoryName(); String relativeDeployDir = dest.getDeployDir(); // paranoia, if no deploy dir is given, as assume it will be directly under the base location if (relativeDeployDir == null || relativeDeployDir.trim().length() == 0) { relativeDeployDir = File.separator; } // get the resource entity stored in our local inventory InventoryManager im = getInventoryManager(); Resource resource = bundleResourceDeployment.getResource(); ResourceContainer container = im.getResourceContainer(resource); resource = container.getResource(); // find out the type of base location that is specified by the bundle destination BundleDestinationBaseDirectory bundleDestBaseDir = null; ResourceTypeBundleConfiguration rtbc = resource.getResourceType().getResourceTypeBundleConfiguration(); if (rtbc == null) { throw new IllegalArgumentException( "The resource type doesn't support bundle deployments: " + resource); } for (BundleDestinationBaseDirectory bdbd : rtbc.getBundleDestinationBaseDirectories()) { if (bdbd.getName().equals(destBaseDirName)) { bundleDestBaseDir = bdbd; break; } } if (bundleDestBaseDir == null) { throw new IllegalArgumentException( "The resource type doesn't support bundle destination base location named [" + destBaseDirName + "]"); } // based on the type of destination base location, determine the root base directory String destBaseDirValueName = bundleDestBaseDir.getValueName(); // the name we look up in the given context String baseLocation; switch (bundleDestBaseDir.getValueContext()) { case fileSystem: { if (!new File(relativeDeployDir).isAbsolute()) { // the deploy dir is not absolute; since we need to pin it to something, we assume the // top root directory // unless the descriptor told us to go somewhere else differently baseLocation = destBaseDirValueName; // ultimately this came from the plugin descriptor if (baseLocation == null || baseLocation.trim().length() == 0) { baseLocation = File .separator; // paranoia, if the plugin descriptor didn't specify, assume the // top root directory } } else { baseLocation = null; // so the relativeDeployDir is processed as an absolute dir } break; } case pluginConfiguration: { baseLocation = resource.getPluginConfiguration().getSimpleValue(destBaseDirValueName, null); if (baseLocation == null) { throw new IllegalArgumentException( "Cannot determine the bundle base deployment location - " + "there is no plugin configuration setting for [" + destBaseDirValueName + "]"); } break; } case resourceConfiguration: { baseLocation = resource.getResourceConfiguration().getSimpleValue(destBaseDirValueName, null); if (baseLocation == null) { throw new IllegalArgumentException( "Cannot determine the bundle base deployment location - " + "there is no resource configuration setting for [" + destBaseDirValueName + "]"); } break; } case measurementTrait: { baseLocation = getMeasurementManager().getTraitValue(container, destBaseDirValueName); if (baseLocation == null) { throw new IllegalArgumentException( "Cannot obtain trait [" + destBaseDirName + "] for resource [" + resource.getName() + "]"); } break; } default: { throw new IllegalArgumentException( "Unknown bundle destination location context: " + bundleDestBaseDir); } } File destDir = new File(baseLocation, relativeDeployDir); if (!destDir.isAbsolute()) { throw new IllegalArgumentException( "The base location path specified by [" + destBaseDirValueName + "] in the context [" + bundleDestBaseDir.getValueContext() + "] along with the destination directory of [" + relativeDeployDir + "] did not resolve to an absolute path [" + destDir.getPath() + "] so there is no way to know where to put the bundle."); } return destDir; }