Repository: brooklyn-server Updated Branches: refs/heads/master e040f074f -> 7807a3e34
Add test of REST /v1/server/ha/persist/export Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/36136d63 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/36136d63 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/36136d63 Branch: refs/heads/master Commit: 36136d63af8256c9e824db1f63b8b0dab1250f70 Parents: e040f07 Author: Aled Sage <aled.s...@gmail.com> Authored: Wed Jun 20 15:17:13 2018 +0100 Committer: Aled Sage <aled.s...@gmail.com> Committed: Wed Jun 20 15:17:13 2018 +0100 ---------------------------------------------------------------------- .../brooklyn/rest/resources/ServerResource.java | 2 +- .../rest/resources/ServerResourceTest.java | 39 +++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/36136d63/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java index 3c59624..9c117bd 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java @@ -483,7 +483,7 @@ public class ServerResource extends AbstractBrooklynRestResource implements Serv dir = ((FileBasedObjectStore)targetStore).getBaseDir(); // only register the parent dir because that will prevent leaks for the random ID Os.deleteOnExitEmptyParentsUpTo(dir.getParentFile(), dir.getParentFile()); - BrooklynPersistenceUtils.writeMemento(mgmt(), targetStore, preferredOrigin); + BrooklynPersistenceUtils.writeMemento(mgmt(), targetStore, preferredOrigin); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ArchiveBuilder.zip().addDirContentsAt( ((FileBasedObjectStore)targetStore).getBaseDir(), ((FileBasedObjectStore)targetStore).getBaseDir().getName() ).stream(baos); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/36136d63/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ServerResourceTest.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ServerResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ServerResourceTest.java index e1ca759..786f8db 100644 --- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ServerResourceTest.java +++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ServerResourceTest.java @@ -20,11 +20,22 @@ package org.apache.brooklyn.rest.resources; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import javax.ws.rs.core.Response; + +import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.ImplementedBy; +import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.mgmt.ManagementContext; import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState; import org.apache.brooklyn.core.BrooklynVersion; @@ -33,17 +44,20 @@ import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess; import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessDriver; import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessImpl; +import org.apache.brooklyn.entity.stock.BasicApplication; +import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.rest.domain.HighAvailabilitySummary; import org.apache.brooklyn.rest.domain.VersionSummary; import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest; import org.apache.brooklyn.util.exceptions.Exceptions; +import org.apache.brooklyn.util.text.StringPredicates; +import org.apache.cxf.jaxrs.client.WebClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import javax.ws.rs.core.Response; -import org.apache.cxf.jaxrs.client.WebClient; +import com.google.common.collect.Iterables; @Test(singleThreaded = true, // by using a different suite name we disallow interleaving other tests between the methods of this test class, which wrecks the test fixtures @@ -71,6 +85,27 @@ public class ServerResourceTest extends BrooklynRestResourceTest { } @Test + public void testExportPersistedState() throws Exception { + BasicApplication app = manager.getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)); + Location loc = manager.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); + byte[] zip = client().path("/server/ha/persist/export").get(byte[].class); + + List<String> entryNames = listEntryNames(zip); + assertTrue(Iterables.tryFind(entryNames, StringPredicates.containsLiteral(app.getId())).isPresent(), "entries="+entryNames); + assertTrue(Iterables.tryFind(entryNames, StringPredicates.containsLiteral(loc.getId())).isPresent(), "entries="+entryNames); + } + + private List<String> listEntryNames(byte[] zip) throws Exception { + List<String> result = new ArrayList<>(); + ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(zip)); + ZipEntry entry; + while ((entry = zipInputStream.getNextEntry()) != null) { + result.add(entry.getName()); + } + return result; + } + + @Test public void testGetHighAvailability() throws Exception { // Note by default management context from super is started without HA enabled. // Therefore can only assert a minimal amount of stuff.