Skip to content

Commit

Permalink
GEODE-7398: implement get single deployment end point (apache#4455)
Browse files Browse the repository at this point in the history
Co-authored-by: Dale Emery <[email protected]>
  • Loading branch information
jinmeiliao and demery-pivotal authored Dec 10, 2019
1 parent ea65f4d commit 37eb8b4
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.apache.geode.management.internal.rest;

import static org.apache.geode.test.junit.assertions.ClusterManagementListResultAssert.assertManagementListResult;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;

import org.apache.commons.io.FilenameUtils;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import org.apache.geode.management.api.ClusterManagementException;
import org.apache.geode.management.api.ClusterManagementListResult;
import org.apache.geode.management.api.ClusterManagementService;
import org.apache.geode.management.client.ClusterManagementServiceBuilder;
import org.apache.geode.management.configuration.Deployment;
import org.apache.geode.management.runtime.DeploymentInfo;
import org.apache.geode.test.compiler.JarBuilder;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.assertions.ClusterManagementListResultAssert;
import org.apache.geode.test.junit.rules.GfshCommandRule;

public class DeployToMultiGroupDUnitTest {
@ClassRule
public static ClusterStartupRule cluster = new ClusterStartupRule();

private static MemberVM locator, server1, server2;

private static ClusterManagementService client;

@ClassRule
public static GfshCommandRule gfsh = new GfshCommandRule();

@ClassRule
public static TemporaryFolder stagingTempDir = new TemporaryFolder();
private static File stagingDir, jar;

@BeforeClass
public static void beforeClass() throws Exception {
// prepare the jars to be deployed
stagingDir = stagingTempDir.newFolder("staging");
jar = new File(stagingDir, "lib.jar");
JarBuilder jarBuilder = new JarBuilder();
jarBuilder.buildJarFromClassNames(jar, "Class1");
locator = cluster.startLocatorVM(0, l -> l.withHttpService());
server1 = cluster.startServerVM(1, "group1", locator.getPort());
server2 = cluster.startServerVM(2, "group2", locator.getPort());

client =
ClusterManagementServiceBuilder.buildWithHostAddress()
.setHostAddress("localhost", locator.getHttpPort())
.build();
gfsh.connect(locator);

gfsh.executeAndAssertThat("deploy --group=group1 --jar=" + jar.getAbsolutePath())
.statusIsSuccess();
gfsh.executeAndAssertThat("deploy --group=group2 --jar=" + jar.getAbsolutePath())
.statusIsSuccess();
}

@Test
public void listAll() {
ClusterManagementListResult<Deployment, DeploymentInfo> list = client.list(new Deployment());
ClusterManagementListResultAssert<Deployment, DeploymentInfo> resultAssert =
assertManagementListResult(list).isSuccessful();
resultAssert.hasConfigurations().extracting(Deployment::getJarFileName)
.containsExactlyInAnyOrder("lib.jar", "lib.jar");
resultAssert.hasRuntimeInfos().extracting(DeploymentInfo::getJarLocation).extracting(
FilenameUtils::getName)
.containsExactlyInAnyOrder("lib.v1.jar", "lib.v1.jar");
}

@Test
public void listByGroup() throws Exception {
Deployment filter = new Deployment();
filter.setGroup("group1");
ClusterManagementListResult<Deployment, DeploymentInfo> list = client.list(filter);
ClusterManagementListResultAssert<Deployment, DeploymentInfo> resultAssert =
assertManagementListResult(list).isSuccessful();
resultAssert.hasConfigurations().extracting(Deployment::getJarFileName)
.containsExactlyInAnyOrder("lib.jar");
resultAssert.hasRuntimeInfos().extracting(DeploymentInfo::getJarLocation).extracting(
FilenameUtils::getName).containsExactlyInAnyOrder("lib.v1.jar");
}

@Test
public void listById() throws Exception {
Deployment filter = new Deployment();
filter.setJarFileName("lib.jar");
ClusterManagementListResult<Deployment, DeploymentInfo> list = client.list(filter);
ClusterManagementListResultAssert<Deployment, DeploymentInfo> resultAssert =
assertManagementListResult(list).isSuccessful();
resultAssert.hasConfigurations().extracting(Deployment::getJarFileName)
.containsExactlyInAnyOrder("lib.jar", "lib.jar");
resultAssert.hasRuntimeInfos().extracting(DeploymentInfo::getJarLocation).extracting(
FilenameUtils::getName).containsExactlyInAnyOrder("lib.v1.jar", "lib.v1.jar");
}

@Test
public void getById() throws Exception {
Deployment filter = new Deployment();
filter.setJarFileName("lib.jar");
assertThatThrownBy(() -> client.get(filter)).isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ERROR: Expect only one matching Deployment.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.apache.geode.management.internal.rest;

import static org.apache.geode.test.junit.assertions.ClusterManagementGetResultAssert.assertManagementGetResult;
import static org.apache.geode.test.junit.assertions.ClusterManagementListResultAssert.assertManagementListResult;

import java.io.File;
Expand All @@ -25,6 +26,7 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import org.apache.geode.management.api.ClusterManagementGetResult;
import org.apache.geode.management.api.ClusterManagementListResult;
import org.apache.geode.management.api.ClusterManagementService;
import org.apache.geode.management.client.ClusterManagementServiceBuilder;
Expand All @@ -33,6 +35,7 @@
import org.apache.geode.test.compiler.JarBuilder;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.assertions.ClusterManagementGetResultAssert;
import org.apache.geode.test.junit.assertions.ClusterManagementListResultAssert;
import org.apache.geode.test.junit.rules.GfshCommandRule;

Expand All @@ -49,19 +52,19 @@ public class DeploymentManagementDUnitTest {

@ClassRule
public static TemporaryFolder stagingTempDir = new TemporaryFolder();
private static File stagingDir, jar1, jar2, jar3;
private static File stagingDir, group1Jar, group2Jar, clusterJar;

@BeforeClass
public static void beforeClass() throws Exception {
// prepare the jars to be deployed
stagingDir = stagingTempDir.newFolder("staging");
jar1 = new File(stagingDir, "jar1.jar");
jar2 = new File(stagingDir, "jar2.jar");
jar3 = new File(stagingDir, "jar3.jar");
group1Jar = new File(stagingDir, "group1.jar");
group2Jar = new File(stagingDir, "group2.jar");
clusterJar = new File(stagingDir, "cluster.jar");
JarBuilder jarBuilder = new JarBuilder();
jarBuilder.buildJarFromClassNames(jar1, "Class1");
jarBuilder.buildJarFromClassNames(jar2, "Class2");
jarBuilder.buildJarFromClassNames(jar3, "Class3");
jarBuilder.buildJarFromClassNames(group1Jar, "Class1");
jarBuilder.buildJarFromClassNames(group2Jar, "Class2");
jarBuilder.buildJarFromClassNames(clusterJar, "Class3");

locator = cluster.startLocatorVM(0, l -> l.withHttpService());
server1 = cluster.startServerVM(1, "group1", locator.getPort());
Expand All @@ -73,11 +76,11 @@ public static void beforeClass() throws Exception {
.build();
gfsh.connect(locator);

gfsh.executeAndAssertThat("deploy --group=group1 --jar=" + jar1.getAbsolutePath())
gfsh.executeAndAssertThat("deploy --group=group1 --jar=" + group1Jar.getAbsolutePath())
.statusIsSuccess();
gfsh.executeAndAssertThat("deploy --group=group2 --jar=" + jar2.getAbsolutePath())
gfsh.executeAndAssertThat("deploy --group=group2 --jar=" + group2Jar.getAbsolutePath())
.statusIsSuccess();
gfsh.executeAndAssertThat("deploy --jar=" + jar3.getAbsolutePath()).statusIsSuccess();
gfsh.executeAndAssertThat("deploy --jar=" + clusterJar.getAbsolutePath()).statusIsSuccess();
}

@Test
Expand All @@ -86,10 +89,11 @@ public void listAll() {
ClusterManagementListResultAssert<Deployment, DeploymentInfo> resultAssert =
assertManagementListResult(list).isSuccessful();
resultAssert.hasConfigurations().extracting(Deployment::getJarFileName)
.containsExactlyInAnyOrder("jar1.jar", "jar2.jar", "jar3.jar");
.containsExactlyInAnyOrder("group1.jar", "group2.jar", "cluster.jar");
resultAssert.hasRuntimeInfos().extracting(DeploymentInfo::getJarLocation).extracting(
FilenameUtils::getName)
.containsExactlyInAnyOrder("jar1.v1.jar", "jar2.v1.jar", "jar3.v1.jar", "jar3.v1.jar");
.containsExactlyInAnyOrder("group1.v1.jar", "group2.v1.jar", "cluster.v1.jar",
"cluster.v1.jar");
}

@Test
Expand All @@ -100,21 +104,33 @@ public void listByGroup() throws Exception {
ClusterManagementListResultAssert<Deployment, DeploymentInfo> resultAssert =
assertManagementListResult(list).isSuccessful();
resultAssert.hasConfigurations().extracting(Deployment::getJarFileName)
.containsExactlyInAnyOrder("jar1.jar");
.containsExactlyInAnyOrder("group1.jar");
resultAssert.hasRuntimeInfos().extracting(DeploymentInfo::getJarLocation).extracting(
FilenameUtils::getName).containsExactlyInAnyOrder("jar1.v1.jar");
FilenameUtils::getName).containsExactlyInAnyOrder("group1.v1.jar");
}

@Test
public void listById() throws Exception {
Deployment filter = new Deployment();
filter.setJarFileName("jar3.jar");
filter.setJarFileName("cluster.jar");
ClusterManagementListResult<Deployment, DeploymentInfo> list = client.list(filter);
ClusterManagementListResultAssert<Deployment, DeploymentInfo> resultAssert =
assertManagementListResult(list).isSuccessful();
resultAssert.hasConfigurations().extracting(Deployment::getJarFileName)
.containsExactlyInAnyOrder("jar3.jar");
.containsExactlyInAnyOrder("cluster.jar");
resultAssert.hasRuntimeInfos().extracting(DeploymentInfo::getJarLocation).extracting(
FilenameUtils::getName).containsExactlyInAnyOrder("jar3.v1.jar", "jar3.v1.jar");
FilenameUtils::getName).containsExactlyInAnyOrder("cluster.v1.jar", "cluster.v1.jar");
}

@Test
public void getById() throws Exception {
Deployment filter = new Deployment();
filter.setJarFileName("cluster.jar");
ClusterManagementGetResult<Deployment, DeploymentInfo> result = client.get(filter);
ClusterManagementGetResultAssert<Deployment, DeploymentInfo> resultAssert =
assertManagementGetResult(result).isSuccessful();
resultAssert.hasConfiguration().extracting(Deployment::getJarFileName).isEqualTo("cluster.jar");
resultAssert.hasRuntimeInfos().extracting(DeploymentInfo::getJarLocation).extracting(
FilenameUtils::getName).containsExactlyInAnyOrder("cluster.v1.jar", "cluster.v1.jar");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.apache.geode.management.api.ClusterManagementGetResult;
import org.apache.geode.management.api.ClusterManagementListResult;
import org.apache.geode.management.configuration.Deployment;
import org.apache.geode.management.runtime.DeploymentInfo;
Expand All @@ -48,4 +50,16 @@ public ClusterManagementListResult<Deployment, DeploymentInfo> list(
}
return clusterManagementService.list(deployment);
}

@ApiOperation(value = "get deployed")
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
@GetMapping(Deployment.DEPLOYMENT_ENDPOINT + "/{id:.+}")
public ClusterManagementGetResult<Deployment, DeploymentInfo> getDeployed(
@PathVariable(name = "id") String id) {
Deployment deployment = new Deployment();
if (StringUtils.isNotBlank(id)) {
deployment.setJarFileName(id);
}
return clusterManagementService.get(deployment);
}
}

0 comments on commit 37eb8b4

Please sign in to comment.