Integer prevDeploymentId = liveDeployment.getReplacedBundleDeploymentId(); if (null == prevDeploymentId) { throw new IllegalArgumentException( checkDeployBundleAuthz(subject, liveDeployment.getBundleVersion().getBundle().getId(), liveDeployment .getDestination().getGroup().getId()); String name = getBundleDeploymentNameImpl(subject, liveDeployment.getDestination(), null, prevDeployment); String desc = (null != deploymentDescription) ? deploymentDescription : prevDeployment.getDescription(); Configuration config = (null == prevDeployment.getConfiguration()) ? null : prevDeployment.getConfiguration() .deepCopy(false); BundleDeployment revertDeployment = bundleManager.createBundleDeploymentInNewTrans(subject, prevDeployment .getBundleVersion().getId(), bundleDestinationId, name, desc, config); return scheduleBundleDeploymentImpl(subject, revertDeployment.getId(), isCleanDeployment, true, prevDeployment.getReplacedBundleDeploymentId());
public void addBundleDeployment(BundleDeployment bundleDeployment) { this.bundleDeployments.add(bundleDeployment); bundleDeployment.setBundleVersion(this); }
@Override public void _finalizePurge(Subject subject, BundleDeployment bundleDeployment, Map<BundleResourceDeployment, String> failedToPurge) throws Exception { bundleDeployment = entityManager.find(BundleDeployment.class, bundleDeployment.getId()); if (failedToPurge.isEmpty()) { bundleDeployment.setLive(false); // all deployments are purged, no where is this live anymore bundleDeployment.setErrorMessage(null); bundleDeployment.setStatus(BundleDeploymentStatus.SUCCESS); } else { bundleDeployment.setLive(true); // not all deployments are purged - error indicates it is still live somewhere StringBuilder errorStr = new StringBuilder(); int totalDeployments = bundleDeployment.getResourceDeployments().size(); int failedPurges = failedToPurge.size(); if (failedPurges < totalDeployments) { bundleDeployment.setStatus(BundleDeploymentStatus.MIXED); // some deployments were purged, so show MIXED status errorStr.append("Failed to purge [").append(failedPurges).append("] of [").append(totalDeployments) .append("] remote resource deployments"); } else { bundleDeployment.setStatus(BundleDeploymentStatus.FAILURE); // all deployments failed to be purged errorStr.append("Failed to purge all [").append(failedPurges).append("] remote resource deployments"); } // key is the resource deployment that failed to be purged; value is the error message for (Map.Entry<BundleResourceDeployment, String> entry : failedToPurge.entrySet()) { errorStr.append("\n\n"); errorStr.append(entry.getKey().getResource().getName()).append(": ").append(entry.getValue()); } bundleDeployment.setErrorMessage(errorStr.toString()); } }
BundleDeployment deployment = entityManager.find(BundleDeployment.class, bundleDeploymentId); if (deployment.getStatus().isTerminal()) { return deployment.getStatus(); List<BundleResourceDeployment> deployments = deployment.getResourceDeployments(); boolean someInProgress = false; boolean someSuccess = false; deployment.setStatus(BundleDeploymentStatus.IN_PROGRESS); } else if (someSuccess) { deployment.setStatus(someFailure ? BundleDeploymentStatus.MIXED : BundleDeploymentStatus.SUCCESS); } else { deployment.setStatus(BundleDeploymentStatus.FAILURE); return deployment.getStatus();
@Override public void deleteBundleDeployment(Subject subject, int bundleDeploymentId) throws Exception { BundleDeployment doomed = this.entityManager.find(BundleDeployment.class, bundleDeploymentId); if (null == doomed) { return; } checkDeployBundleAuthz(subject, doomed.getBundleVersion().getBundle().getId(), doomed.getDestination() .getGroup().getId()); // only allow deployments to be deleted if they are not started or finished if (BundleDeploymentStatus.PENDING == doomed.getStatus() || BundleDeploymentStatus.SUCCESS == doomed.getStatus() || BundleDeploymentStatus.FAILURE == doomed.getStatus() || BundleDeploymentStatus.MIXED == doomed.getStatus()) { // change the pointer like in the linked list (ie. when removing B from A -> B -> C, it should result // in following situation: A -> C) Query q = entityManager.createNamedQuery(BundleDeployment.QUERY_UPDATE_FOR_DEPLOYMENT_REMOVE); q.setParameter("bundleId", doomed.getId()); q.executeUpdate(); entityManager.flush(); entityManager.remove(doomed); } else { throw new IllegalArgumentException("Can not delete deployment with status [" + doomed.getStatus() + "]"); } }
BundleDestination destination = newDeployment.getDestination(); ResourceGroup group = destination.getGroup(); checkDeployBundleAuthz(subject, newDeployment.getBundleVersion().getBundle().getId(), group.getId()); if (null != currentDeployments) { for (BundleDeployment d : currentDeployments) { if (d.isLive()) { d.setLive(false); if (!isRevert) { newDeployment.setReplacedBundleDeploymentId(d.getId()); } else { newDeployment.setReplacedBundleDeploymentId(revertedDeploymentReplacedDeployment); newDeployment.setLive(true);
static File baseDirFor(BundleResourceDeployment rd, Configuration referencedConfiguration) { File root = getMetadataRoot(referencedConfiguration); return baseDirFor(rd.getBundleDeployment().getDestination().getId(), root); }
List<BundleResourceDeployment> resourceDeploys = liveDeployment.getResourceDeployments(); if (resourceDeploys == null || resourceDeploys.isEmpty()) { return; // nothing to do checkDeployBundleAuthz(subject, liveDeployment.getBundleVersion().getBundle().getId(), liveDeployment .getDestination().getGroup().getId()); bvc.addFilterId(liveDeployment.getBundleVersion().getId()); bvc.fetchBundle(true); // will eagerly fetch the bundle type PageList<BundleVersion> bvs = bundleManager.findBundleVersionsByCriteria(subject, bvc); liveDeployment.setBundleVersion(bvs.get(0)); // wire up the full bundle version back into the live deployment rtc.addFilterBundleTypeId(liveDeployment.getBundleVersion().getBundle().getBundleType().getId()); PageList<ResourceType> rts = resourceTypeManager.findResourceTypesByCriteria(subject, rtc); liveDeployment.getBundleVersion().getBundle().getBundleType().setResourceType(rts.get(0)); int totalDeployments = liveDeployment.getResourceDeployments().size(); int failedPurges = failedToPurge.size(); throw new Exception("Failed to purge [" + failedPurges + "] of [" + totalDeployments
} else { try { String liveName = liveDeployment.getName(); int iStart = liveName.indexOf("[") + 1, iEnd = liveName.indexOf("]"); deploy = Integer.valueOf(liveName.substring(iStart, iEnd)) + 1; deploymentName = "Deployment [" + deploy + "] of Version [" + version + "] to [" + dest + "]"; } else { String liveVersion = liveDeployment.getBundleVersion().getVersion(); if (liveVersion.equals(version)) { deploymentName = "Deployment [" + deploy + "] Revert To: " + prevDeployment.getName();
subjectManager.getOverlord(), deployment.getId(), bundleTargetResourceId); AUDIT_ACTION_DEPLOYMENT_REQUESTED, deployment.getName(), null, BundleResourceDeploymentHistory.Status.SUCCESS, "Requested deployment time: " + request.getRequestedDeployTimeAsString(), null); resourceDeployment.getId(), BundleDeploymentStatus.FAILURE); history = new BundleResourceDeploymentHistory(subject.getName(), AUDIT_ACTION_DEPLOYMENT, deployment.getName(), null, BundleResourceDeploymentHistory.Status.FAILURE, response.getErrorMessage(), null); bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subject, resourceDeployment.getId(), AUDIT_ACTION_DEPLOYMENT, deployment.getName(), null, BundleResourceDeploymentHistory.Status.FAILURE, "Failed to schedule, agent on [" + bundleTarget + "] may be down: " + t, null); BundleDeploymentStatus.FAILURE); BundleResourceDeploymentHistory history = new BundleResourceDeploymentHistory(subject.getName(), AUDIT_ACTION_DEPLOYMENT, deployment.getName(), null, BundleResourceDeploymentHistory.Status.FAILURE, "Target resource is not of a type that can have bundles deployed to it [resource=" + bundleTarget.getName() + "; id=" + bundleTarget.getId() + "]. Fix target group for destination [" + deployment.getDestination().getName() + "]", null); bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subject, resourceDeployment.getId(), history);
bdc.addFilterId(resourceDeployment.getBundleDeployment().getId()); bdc.fetchBundleVersion(true); bdc.fetchConfiguration(true); bc.addFilterDestinationId(deployment.getDestination().getId()); Bundle bundle = bundleManager.findBundlesByCriteria(subject, bc).get(0); bundle.getBundleType().setResourceType(resourceType); deployment.getBundleVersion().setBundle(bundle); deployment.getDestination().setBundle(bundle);
private BundleDeployment createBundleDeploymentImpl(Subject subject, BundleVersion bundleVersion, BundleDestination bundleDestination, String name, String description, Configuration configuration) throws Exception { ConfigurationDefinition configDef = bundleVersion.getConfigurationDefinition(); if (null != configDef) { if (null == configuration) { throw new IllegalArgumentException( "Missing Configuration. Configuration is required when the specified BundleVersion defines Configuration Properties."); } // passing in the default configuration will make sure that the readonly properties with the non-null // default values defined in the config def cannot be overridden by the caller. // Those properties are meant to be set by the bundle plugins, not by the user. Configuration defaultConfig = ConfigurationUtility.createDefaultConfiguration(configDef); List<String> errors = ConfigurationUtility.validateConfiguration(configuration, defaultConfig, configDef); if (!errors.isEmpty()) { throw new IllegalArgumentException("Invalid Configuration: " + errors.toString()); } } BundleDeployment deployment = new BundleDeployment(bundleVersion, bundleDestination, name); deployment.setDescription(description); deployment.setConfiguration(configuration); deployment.setSubjectName(subject.getName()); PropertySimple discoveryDelayProperty = configuration.getSimple("org.rhq.discoveryDelay"); if(discoveryDelayProperty != null) { deployment.setDiscoveryDelay(discoveryDelayProperty.getIntegerValue()); } entityManager.persist(deployment); return deployment; }
private Result<String[]> getPids(BundleResourceDeployment rd, String operation) { PropertySimple patchType = rd.getBundleDeployment().getConfiguration().getSimple("patchType"); boolean isBundle = patchType != null && "patch-bundle".equals(patchType.getStringValue()); PropertySimple patchIdProp = rd.getBundleDeployment().getConfiguration() .getSimple("patchId"); PropertySimple allPatchIdsProp = rd.getBundleDeployment().getConfiguration() .getSimple("allPatchIds"); String[] pids; if (isBundle) { if (allPatchIdsProp == null || allPatchIdsProp.getStringValue() == null) { return new Result<String[]>(null, "Could not determine the list of patch ids from the bundle configuration while performing " + operation); } pids = allPatchIdsProp.getStringValue().split("#"); //we need to return the pids in the same order as patch history - i.e. in the reversed deployment order Collections.reverse(Arrays.asList(pids)); } else { if (patchIdProp == null || patchIdProp.getStringValue() == null) { return new Result<String[]>(null, "Could not determine the list of patch ids from the bundle configuration while performing " + operation); } pids = new String[1]; pids[0] = patchIdProp.getStringValue(); } return new Result<String[]>(pids, null); }
private void completeDeployment(final BundleResourceDeployment resourceDeployment, BundleDeploymentStatus status, String message) { getBundleServerService().setBundleDeploymentStatus(resourceDeployment.getId(), status); BundleResourceDeploymentHistory.Status auditStatus = null; if(BundleDeploymentStatus.SUCCESS == status) { auditStatus = BundleResourceDeploymentHistory.Status.SUCCESS; Integer discoveryDelay = resourceDeployment.getBundleDeployment().getDiscoveryDelay(); if(discoveryDelay == null) { discoveryDelay = Integer.valueOf(0); // Fallback } if(!(discoveryDelay.intValue() < 0)) { inventoryManager.executeServiceScanDeferred(resourceDeployment.getResource().getId(), discoveryDelay * 1000); } } else { auditStatus = BundleResourceDeploymentHistory.Status.FAILURE; } auditDeployment(resourceDeployment, AUDIT_DEPLOYMENT_ENDED, resourceDeployment.getBundleDeployment().getName(), null, auditStatus, message, null); }
/** * Calling this method with a non-<code>null</code> error message implies that the request's status is * {@link ConfigurationUpdateStatus#FAILURE}. The inverse is <i>not</i> true - that is, if you set the error message * to <code>null</code>, the status is left as-is; it will not assume that a <code>null</code> error message means * the status is successful. * * @param errorMessage */ public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; if (this.errorMessage != null) { setStatus(BundleDeploymentStatus.FAILURE); } }
BundleVersion bundleVersion = bundleDeployment.getBundleVersion();
public void addBundleDeployment(BundleDeployment bundleDeployment) { if (bundleDeployments == null) { bundleDeployments = new HashSet<BundleDeployment>(); } bundleDeployment.addTag(this); bundleDeployments.add(bundleDeployment); }
return false; } else if (!bundleDeployment.equals(other.bundleDeployment)) { return false;
BundleDestination dest = bundleResourceDeployment.getBundleDeployment().getDestination(); String destBaseDirName = dest.getDestinationBaseDirectoryName(); String relativeDeployDir = dest.getDeployDir();
BundleType bundleType = bundleDeployment.getBundleVersion().getBundle().getBundleType(); ResourceType resourceType = bundleType.getResourceType(); Set<Resource> resources = inventoryManager.getResourcesWithType(resourceType); auditDeployment(resourceDeployment, AUDIT_DEPLOYMENT_SCHEDULED, bundleDeployment.getName(), "Scheduled deployment time: " + request.getRequestedDeployTimeAsString());