@Override public BundleDeployment createBundleDeployment(Subject subject, int bundleVersionId, int bundleDestinationId, String description, Configuration configuration) throws Exception { BundleVersion bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId); if (null == bundleVersion) { throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId); } BundleDestination bundleDestination = entityManager.find(BundleDestination.class, bundleDestinationId); if (null == bundleDestination) { throw new IllegalArgumentException("Invalid bundleDestinationId: " + bundleDestinationId); } checkDeployBundleAuthz(subject, bundleVersion.getBundle().getId(), bundleDestination.getGroup().getId()); String name = getBundleDeploymentNameImpl(subject, bundleDestination, bundleVersion, null); return this.createBundleDeploymentImpl(subject, bundleVersion, bundleDestination, name, description, configuration); }
public void addDestination(BundleDestination destination) { this.destinations.add(destination); destination.setBundle(this); }
@Override public void deleteBundleDestination(Subject subject, int destinationId) throws Exception { BundleDestination doomed = this.entityManager.find(BundleDestination.class, destinationId); if (null == doomed) { return; } checkDeployBundleAuthz(subject, doomed.getBundle().getId(), doomed.getGroup().getId()); // deployments replace other deployments and have a self-referring FK. The deployments // need to be removed in a way that will ensure that a replaced deployment is not removed // prior to the replacer. To do this we'll just blanket update all the doomed deployments // to break the FK dependency with nulls. Query q = entityManager.createNamedQuery(BundleDeployment.QUERY_UPDATE_FOR_DESTINATION_REMOVE); q.setParameter("destinationId", destinationId); q.executeUpdate(); entityManager.flush(); entityManager.remove(doomed); }
ResourceGroup group = destination.getGroup(); destination = entityManager.find(BundleDestination.class, destination.getId()); List<BundleDeployment> currentDeployments = destination.getDeployments(); if (null != currentDeployments) { for (BundleDeployment d : currentDeployments) {
rd.getBundleDeployment().getDestination().getName()); if (saveDestinationName.failed()) { return saveDestinationName.errorMessage;
BundleDestination dest = new BundleDestination(bundle, name, group, destinationSpecification, deployDir); dest.setDescription(description); entityManager.persist(dest);
String destBaseDirName = dest.getDestinationBaseDirectoryName(); String relativeDeployDir = dest.getDeployDir();
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; }
public void addBundleDestination(BundleDestination bundleDestination) { if (bundleDestinations == null) { bundleDestinations = new HashSet<BundleDestination>(); } bundleDestination.addTag(this); bundleDestinations.add(bundleDestination); }
return false; } else if (!this.destination.equals(other.destination)) { return false;
"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);
@Override public String getBundleDeploymentName(Subject subject, int bundleDestinationId, int bundleVersionId, int prevDeploymentId) { BundleDestination bundleDestination = entityManager.find(BundleDestination.class, bundleDestinationId); if (null == bundleDestination) { throw new IllegalArgumentException("Invalid bundleDestinationId: " + bundleDestinationId); } BundleVersion bundleVersion = null; BundleDeployment prevDeployment = null; if (bundleVersionId > 0) { bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId); if (null == bundleVersion) { throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId); } } else if (prevDeploymentId > 0) { prevDeployment = entityManager.find(BundleDeployment.class, prevDeploymentId); if (null == prevDeployment) { throw new IllegalArgumentException("Invalid prevDeploymentId: " + prevDeploymentId); } } else { throw new IllegalArgumentException("Must specify either a valid bundleVersionId [" + bundleVersionId + "] or prevDeploymentId [" + prevDeploymentId + "]"); } if (bundleVersion != null) { checkDeployBundleAuthz(subject, bundleVersion.getBundle().getId(), bundleDestination.getGroup().getId()); } return getBundleDeploymentNameImpl(subject, bundleDestination, bundleVersion, prevDeployment); }
static File baseDirFor(BundleResourceDeployment rd, Configuration referencedConfiguration) { File root = getMetadataRoot(referencedConfiguration); return baseDirFor(rd.getBundleDeployment().getDestination().getId(), root); }
@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() + "]"); } }
int destinationId = resourceDeployment.getBundleDeployment().getDestination().getId(); int activeDestinationId = metadata.result.getDestinationId();
@Override public PageList<BundleDeployment> findBundleDeploymentsByCriteria(Subject subject, BundleDeploymentCriteria criteria) { CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); // filter by bundles that are viewable if (!authorizationManager.hasGlobalPermission(subject, Permission.VIEW_BUNDLES)) { generator.setAuthorizationBundleFragment(CriteriaQueryGenerator.AuthorizationTokenType.BUNDLE, subject.getId(), "bundleVersion.bundle"); } CriteriaQueryRunner<BundleDeployment> queryRunner = new CriteriaQueryRunner<BundleDeployment>(criteria, generator, entityManager); PageList<BundleDeployment> result = queryRunner.execute(); // The result currently holds bundle deployments for bundles viewable by the caller, but we must remove // those bundle deployments for destinations not viewable by the user. In essence we wanted two authz tokens, // one for bundle and one for resource group, but we can only supply one. if (!(result.isEmpty() || authorizationManager.isInventoryManager(subject))) { for (Iterator<BundleDeployment> i = result.iterator(); i.hasNext();) { BundleDeployment bd = i.next(); int groupId = bd.getDestination().getGroup().getId(); if (!authorizationManager.canViewGroup(subject, groupId)) { i.remove(); } } } return result; }
.getDestination().getGroup().getId());