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); }
public void addResourceDeployment(BundleResourceDeployment resourceDeployment) { if (null == this.resourceDeployments) { resourceDeployments = new ArrayList<BundleResourceDeployment>(); } this.resourceDeployments.add(resourceDeployment); resourceDeployment.setBundleDeployment(this); }
@Override public String toString() { StringBuilder str = new StringBuilder(this.getClass() + ": "); str.append("live-deployment=[").append(resourceDeployment.toString()).append("]"); return str.toString(); } }
BundleDestination dest = bundleResourceDeployment.getBundleDeployment().getDestination(); String destBaseDirName = dest.getDestinationBaseDirectoryName(); String relativeDeployDir = dest.getDeployDir(); Resource resource = bundleResourceDeployment.getResource(); ResourceContainer container = inventoryManager.getResourceContainer(resource); resource = container.getResource();
static File baseDirFor(BundleResourceDeployment rd, Configuration referencedConfiguration) { File root = getMetadataRoot(referencedConfiguration); return baseDirFor(rd.getBundleDeployment().getDestination().getId(), root); }
rc.addFilterId(resourceDeployment.getResource().getId()); rc.fetchTags(true); Resource resource = resourceManager.findResourcesByCriteria(subject, rc).get(0); resourceDeployment.setResource(resource); bdc.addFilterId(resourceDeployment.getBundleDeployment().getId()); bdc.fetchBundleVersion(true); bdc.fetchConfiguration(true); deployment.getDestination().setBundle(bundle); resourceDeployment.setBundleDeployment(deployment);
resourceDeployIds.add(resourceDeploy.getId()); brd.setBundleDeployment(liveDeployment); BundleResourceDeploymentHistory.Status.SUCCESS, null, null); bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subjectManager.getOverlord(), resourceDeploy.getId(), history); AgentClient agentClient = agentManager.getAgentClient(overlord, resourceDeploy.getResource().getId()); BundleAgentService bundleAgentService = agentClient.getBundleAgentService(); BundlePurgeRequest request = new BundlePurgeRequest(resourceDeploy);
@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()); } }
@Override public void auditDeployment(BundleResourceDeployment bundleResourceDeployment, String action, String info, BundleResourceDeploymentHistory.Category category, BundleResourceDeploymentHistory.Status status, String message, String attachment) { if (null == action || null == info) { throw new IllegalArgumentException("action or info is null"); } if (null == status) { status = BundleResourceDeploymentHistory.Status.SUCCESS; } BundleResourceDeploymentHistory history = new BundleResourceDeploymentHistory("Bundle Plugin", action, info, category, status, message, attachment); if (LOG.isDebugEnabled()) { LOG.debug("Reporting deployment step [" + history + "] to Server..."); } getBundleServerService().addDeploymentHistory(bundleResourceDeployment.getId(), history); }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public BundleResourceDeploymentHistory addBundleResourceDeploymentHistoryInNewTrans(Subject subject, int resourceDeploymentId, BundleResourceDeploymentHistory history) throws Exception { BundleResourceDeployment resourceDeployment = entityManager.find(BundleResourceDeployment.class, resourceDeploymentId); if (null == resourceDeployment) { throw new IllegalArgumentException("Invalid resourceDeploymentId: " + resourceDeploymentId); } resourceDeployment.addBundleResourceDeploymentHistory(history); this.entityManager.persist(resourceDeployment); return history; }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public BundleResourceDeployment createBundleResourceDeploymentInNewTrans(Subject subject, int bundleDeploymentId, int resourceId) throws Exception { BundleDeployment deployment = entityManager.find(BundleDeployment.class, bundleDeploymentId); if (null == deployment) { throw new IllegalArgumentException("Invalid bundleDeploymentId: " + bundleDeploymentId); } Resource resource = entityManager.find(Resource.class, resourceId); if (null == resource) { throw new IllegalArgumentException("Invalid resourceId (Resource does not exist): " + resourceId); } BundleResourceDeployment resourceDeployment = new BundleResourceDeployment(deployment, resource); entityManager.persist(resourceDeployment); return resourceDeployment; }
@Override public List<BundleResourceDeploymentHistory> getBundleResourceDeploymentHistories(Subject subject, int resourceDeploymentId) { // First check if this user can actually see this resource deployment // by calling #findBundleResourceDeploymentsByCriteria) BundleResourceDeploymentCriteria criteria = new BundleResourceDeploymentCriteria(); criteria.addFilterId(resourceDeploymentId); criteria.fetchHistories(true); criteria.setPageControl(PageControl.getSingleRowInstance()); PageList<BundleResourceDeployment> bundleResourceDeploymentsByCriteria = findBundleResourceDeploymentsByCriteria( subject, criteria); if (bundleResourceDeploymentsByCriteria.isEmpty()) { return Collections.emptyList(); } BundleResourceDeployment resourceDeployment = bundleResourceDeploymentsByCriteria.iterator().next(); return new ArrayList<BundleResourceDeploymentHistory>(resourceDeployment.getBundleResourceDeploymentHistories()); }
boolean someFailure = false; for (BundleResourceDeployment rd : deployments) { switch (rd.getStatus()) { case SUCCESS: someSuccess = true;
private String getConnectionString(BundleResourceDeployment resourceDeployment) { ResourceContainer rc = inventoryManager.getResourceContainer(resourceDeployment.getResource()); BundleDestination dest = resourceDeployment.getBundleDeployment().getDestination(); ResourceType type = rc.getResource().getResourceType(); String specName = dest.getDestinationSpecificationName(); String relativeDeployDir = dest.getDeployDir(); Configuration config = new Configuration(); config.put(new PropertySimple("deployDir", relativeDeployDir)); ConnectionStringAvailableProperties props = new ConnectionStringAvailableProperties(rc, measurementManager, config); for (ResourceTypeBundleConfiguration.BundleDestinationSpecification spec : type .getResourceTypeBundleConfiguration().getBundleDestinationSpecifications()) { if (specName.equals(spec.getName())) { ResourceTypeBundleConfiguration.BundleDestinationDefinition def = (ResourceTypeBundleConfiguration.BundleDestinationDefinition) spec; String rawConnectionString = def.getConnectionString(); if (rawConnectionString == null) { return null; } TokenReplacingReader trr = new TokenReplacingReader(new StringReader(rawConnectionString), props); try { return StreamUtil.slurp(trr); } finally { StreamUtil.safeClose(trr); } } } return null; }
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); }
int resourceId = brd.getResource().getId(); resourceIds.add(resourceId); for (Iterator<BundleResourceDeployment> i = result.iterator(); i.hasNext();) { BundleResourceDeployment brd = i.next(); if (brd.getResource().getId() == resourceId.intValue()) { i.remove();
BundleScheduleRequest request = bundleManager.getScheduleRequest(subject, resourceDeployment.getId(), isCleanDeployment, isRevert); + request.getRequestedDeployTimeAsString(), null); bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subjectManager.getOverlord(), resourceDeployment.getId(), history); 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(), history); BundleResourceDeploymentHistory.Status.FAILURE, "Failed to schedule, agent on [" + bundleTarget + "] may be down: " + t, null); bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subject, resourceDeployment.getId(), failureHistory); bundleManager.setBundleResourceDeploymentStatusInNewTransaction(subject, resourceDeployment.getId(), BundleDeploymentStatus.FAILURE); bundleManager.setBundleResourceDeploymentStatusInNewTransaction(subject, resourceDeployment.getId(), 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);
final BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment(); + resourceDeployment.getResource() + "]"; auditDeployment(resourceDeployment, AUDIT_PURGE_STARTED, bundleDeployment.getName(), deploymentMessage);
Configuration deploymentConfiguration = rd.getBundleDeployment().getConfiguration();
@Override public String toString() { StringBuilder str = new StringBuilder(this.getClass() + ": "); str.append("live-deployment-to-be-purge=[").append(resourceDeployment.toString()).append("], "); str.append("target=[").append(destinationTarget.toString()).append("]"); return str.toString(); } }