public void resourceDelete(IPResource resource) { Long internalId = resource.getInternalId(); if (internalId == null) { Optional<IPResource> found = resourceService.resourceFindByPk(resource); if (found.isPresent()) { internalId = found.get().getInternalId(); } } resourceDelete(internalId); }
protected void removeManagedLinkAndDeleteIfNotManagedByAnyoneElse(IPResourceService resourceService, ChangesContext changes, IPResource managedResource, IPResource... removeLinksFrom) { List<? extends IPResource> fromResources = resourceService.linkFindAllByLinkTypeAndToResource(LinkTypeConstants.MANAGES, managedResource); logger.debug("Resource {} is managed by {} other resources", managedResource, fromResources.size()); // Remove the managed links int removedLinks = 0; List<Long> removeLinksFromIds = Arrays.asList(removeLinksFrom).stream().map(IPResource::getInternalId).collect(Collectors.toList()); for (IPResource fromResource : fromResources) { if (removeLinksFromIds.contains(fromResource.getInternalId())) { ++removedLinks; changes.linkDelete(fromResource, LinkTypeConstants.MANAGES, managedResource); } } logger.debug("Resource {} is now managed by {} other resources", managedResource, fromResources.size() - removedLinks); // All managed links removed and not manually edited-> Delete the resource if (fromResources.size() - removedLinks == 0 && managedResource.getResourceEditorName() == null) { changes.resourceDelete(managedResource.getInternalId()); } }
private void removeApplicationFor(CommonServicesContext services, ChangesContext changes, String machineName) { IPResourceService resourceService = services.getResourceService(); // Application Application backupApplication = new Application(); backupApplication.setDescription("Backup to Google Cloud for " + machineName); backupApplication.setName("backup_google-" + machineName.replaceAll("\\.", "_")); Optional<Application> existingApplicationOptional = resourceService.resourceFindByPk(backupApplication); if (existingApplicationOptional.isPresent()) { Application existingApplication = existingApplicationOptional.get(); logger.info("Removing application {}", existingApplication.getName()); changes.resourceDelete(existingApplication); } }
long cleaned = 0; for (DnsEntry dnsEntry : oldDnsEntries) { changes.resourceDelete(dnsEntry); ++cleaned;
private void common(CommonServicesContext services, ChangesContext changes, JunitResource resource) { if (!alwaysUpdate) { return; } List<JunitResource> junitResources = services.getResourceService().resourceFindAll(services.getResourceService().createResourceQuery(JunitResource.class)); if (junitResources.size() < 3) { for (int i = 0; i < 5; ++i) { changes.resourceAdd(new JunitResource(SecureRandomTools.randomHexString(10))); } } else { JunitResource update = junitResources.get(0); JunitResource refresh = junitResources.get(1); JunitResource delete = junitResources.get(2); update.setDate(new Date()); changes.resourceUpdate(update); changes.resourceRefresh(refresh); changes.resourceDelete(delete); } }
@Test public void testChanges_linksAndTagsAreNotKeptWhenDeleted() { // Create ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); JunitResource r1 = new JunitResource("1"); JunitResource r2 = new JunitResource("2"); changes.resourceAdd(r1); changes.resourceAdd(r2); changes.linkAdd(r1, "link1", r2); changes.tagAdd(r1, "tag1"); getInternalServicesContext().getInternalChangeService().changesExecute(changes); IPResourceService resourceService = getCommonServicesContext().getResourceService(); r1 = resourceService.resourceFindByPk(r1).get(); r2 = resourceService.resourceFindByPk(r2).get(); Assert.assertEquals(Arrays.asList("link1"), resourceService.linkFindAllByFromResource(r1).stream().map(it -> it.getA()).sorted().collect(Collectors.toList())); Assert.assertEquals(Arrays.asList("tag1"), resourceService.tagFindAllByResource(r1).stream().sorted().collect(Collectors.toList())); // Delete it changes.resourceDelete(resourceService.resourceFindByPk(r1).get().getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes); Assert.assertEquals(0, resourceService.linkFindAllByFromResource(r1).size()); Assert.assertEquals(0, resourceService.tagFindAllByResource(r1).size()); // Recreate it changes.resourceAdd(r1); getInternalServicesContext().getInternalChangeService().changesExecute(changes); // Check no links and tags Assert.assertEquals(0, resourceService.linkFindAllByFromResource(r1).size()); Assert.assertEquals(0, resourceService.tagFindAllByResource(r1).size()); }
if (existingApplicationOptional.isPresent()) { logger.info("[{}] Deleting existing Backup script", machineName); changes.resourceDelete(existingApplicationOptional.get());
if (existingHaProxyApplicationOptional.isPresent()) { logger.info("[{}] Deleting existing HA Proxy", machineName); changes.resourceDelete(existingHaProxyApplicationOptional.get());
if (existingHaProxyApplicationOptional.isPresent()) { logger.info("[{}] Deleting existing HA Proxy", machineName); changes.resourceDelete(existingHaProxyApplicationOptional.get());
private void deleteAllResources() { ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); for (IPResource resource : getInternalServicesContext().getInternalIPResourceService().resourceFindAll()) { changes.resourceDelete(resource); } getInternalServicesContext().getInternalChangeService().changesExecute(changes); }
changes.resourceDelete(entry.getInternalId());
changes.resourceDelete(m1.getInternalId()); changes.resourceAdd(new Machine("m2.node.example.com")); try {
changes.resourceDelete(entry.getInternalId());
changes.resourceDelete(a2.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes); changes.resourceDelete(a1.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
changes.resourceDelete(website.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
changes.resourceDelete(m2.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes); changes.resourceDelete(dp.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
changes.resourceDelete(c1.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
changes.resourceDelete(machine.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
changes.resourceDelete(loginWebsiteCertificate); changes.resourceDelete(uiWebsiteCertificate); getInternalServicesContext().getInternalChangeService().changesExecute(changes); changes.resourceDelete(infraConfig); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
changes.resourceDelete(m1.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes);