Skip to content

Commit

Permalink
GEODE-8905: Introduce JarDeploymentService (#5989)
Browse files Browse the repository at this point in the history
* GEODE-8905: Introduce JarDeploymentService.
   Unified deploy functionality between REST and GFSH
   Pulled deploy jar functionality into its own module
   Renamed internal *Util classes to *Utils

Co-authored-by: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
  • Loading branch information
yozaner1324 and Udo Kohlmeyer committed Mar 16, 2021
1 parent 5fe934e commit 9637ddd
Show file tree
Hide file tree
Showing 219 changed files with 3,662 additions and 1,714 deletions.
12 changes: 12 additions & 0 deletions boms/geode-all-bom/src/test/resources/expected-pom.xml
Expand Up @@ -451,6 +451,12 @@
<version>0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.modules</groupId>
<artifactId>jboss-modules</artifactId>
<version>1.11.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jgroups</groupId>
<artifactId>jgroups</artifactId>
Expand Down Expand Up @@ -913,6 +919,12 @@
<version>${version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-deployment-legacy</artifactId>
<version>${version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-dunit</artifactId>
Expand Down
Expand Up @@ -158,6 +158,7 @@ class DependencyConstraints implements Plugin<Project> {
api(group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.2.1')
api(group: 'org.httpunit', name: 'httpunit', version: '1.7.3')
api(group: 'org.iq80.snappy', name: 'snappy', version: '0.4')
api(group: 'org.jboss.modules', name: 'jboss-modules', version: get('jboss-modules.version'))
api(group: 'org.jgroups', name: 'jgroups', version: get('jgroups.version'))
api(group: 'org.mockito', name: 'mockito-core', version: '3.8.0')
api(group: 'org.mortbay.jetty', name: 'servlet-api', version: '3.0.20100224')
Expand Down
2 changes: 2 additions & 0 deletions extensions/geode-modules-session/build.gradle
Expand Up @@ -29,6 +29,8 @@ dependencies {
exclude module: 'geode-modules'
}
compile(project(':geode-core'))
implementation(project(':geode-common'))

integrationTestImplementation(project(':extensions:geode-modules'))
integrationTestImplementation(project(':geode-dunit')) {
exclude module: 'geode-core'
Expand Down
3 changes: 2 additions & 1 deletion extensions/geode-modules/build.gradle
Expand Up @@ -25,8 +25,9 @@ evaluationDependsOn(":geode-core")
dependencies {
// main
implementation(platform(project(':boms:geode-all-bom')))
implementation(project(':geode-logging'))
api(project(':geode-logging'))
implementation(project(':geode-membership'))
api(project(':geode-common'))
implementation(project(':geode-serialization'))
implementation('org.slf4j:slf4j-api')

Expand Down
11 changes: 8 additions & 3 deletions extensions/geode-modules/src/test/resources/expected-pom.xml
Expand Up @@ -48,13 +48,18 @@
<dependencies>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-core</artifactId>
<artifactId>geode-logging</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-logging</artifactId>
<scope>runtime</scope>
<artifactId>geode-common</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
Expand Down
1 change: 1 addition & 0 deletions extensions/session-testing-war/build.gradle
Expand Up @@ -24,6 +24,7 @@ apply plugin: 'war'
dependencies {
compile(platform(project(':boms:geode-all-bom')))
implementation('javax.servlet:javax.servlet-api')
implementation(project(':geode-deployment-legacy'))
}

war {
Expand Down
Expand Up @@ -115,12 +115,10 @@ public String getValue() {
*/
private static final String[] tomcatRequiredJars =
{"antlr", "commons-io", "commons-lang", "commons-validator", "fastutil", "geode-common",
"geode-core", "geode-log4j", "geode-logging", "geode-membership", "geode-management",
"geode-serialization",
"geode-tcp-server", "javax.transaction-api", "jgroups", "log4j-api", "log4j-core",
"log4j-jul", "micrometer", "shiro-core", "jetty-server", "jetty-util", "jetty-http",
"jetty-io"};

"geode-core", "geode-deployment-legacy", "geode-log4j", "geode-logging",
"geode-membership", "geode-management", "geode-serialization", "geode-tcp-server",
"javax.transaction-api", "jgroups", "log4j-api", "log4j-core", "log4j-jul", "micrometer",
"shiro-core", "jetty-server", "jetty-util", "jetty-http", "jetty-io"};
private final TomcatVersion version;

private final CommitValve commitValve;
Expand Down
@@ -0,0 +1,261 @@
/*
* 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.modules;


import static org.apache.geode.test.util.ResourceUtils.createTempFileFromResource;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import org.apache.geode.test.compiler.JarBuilder;
import org.apache.geode.test.junit.rules.gfsh.GfshRule;
import org.apache.geode.test.junit.rules.gfsh.GfshScript;

public class DeployJarAcceptanceTest {

@ClassRule
public static GfshRule gfshRule = new GfshRule();

@ClassRule
public static TemporaryFolder stagingTempDir = new TemporaryFolder();

private static File jarFile;
private static File jarFileV2;
private static File anotherJarFile;

@BeforeClass
public static void setup() throws IOException {
File stagingDir = stagingTempDir.newFolder("staging");
jarFile = new File(stagingDir, "myJar-1.0.jar");
jarFileV2 = new File(stagingDir, "myJar-2.0.jar");
anotherJarFile = new File(stagingDir, "anotherJar-1.0.jar");
JarBuilder jarBuilder = new JarBuilder();
jarBuilder.buildJarFromClassNames(jarFile, "SomeClass");
jarBuilder.buildJarFromClassNames(jarFileV2, "SomeClass", "SomeClassVersionTwo");
jarBuilder.buildJarFromClassNames(anotherJarFile, "SomeOtherClass");

GfshScript
.of("start locator --name=locator", "configure pdx --read-serialized=true",
"start server --name=server --locators=localhost[10334]")
.execute(gfshRule);
}

@After
public void teardown() {
System.out.println(GfshScript.of(getLocatorGFSHConnectionString(), "undeploy")
.execute(gfshRule).getOutputText());
}

private String getLocatorGFSHConnectionString() {
return "connect --locator=localhost[10334]";
}

@Test
public void testDeployJar() throws IOException {
GfshScript.of(getLocatorGFSHConnectionString(),
"deploy --jar=" + jarFile.getCanonicalPath()).execute(gfshRule);

assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list deployed")
.execute(gfshRule).getOutputText()).contains(jarFile.getName()).contains("JAR Location");
}

@Test
public void testDeployJarWithDeploymentName() throws IOException {
GfshScript.of(getLocatorGFSHConnectionString(),
"deploy --name=myDeployment --jar=" + jarFile.getCanonicalPath()).execute(gfshRule);

assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list deployed")
.execute(gfshRule).getOutputText()).contains("myDeployment").contains("JAR Location");
}

@Test
public void testUndeployJar() throws IOException {
GfshScript.of(getLocatorGFSHConnectionString(),
"deploy --jar=" + jarFile.getCanonicalPath()).execute(gfshRule);

assertThat(
GfshScript.of(getLocatorGFSHConnectionString(),
"undeploy --jar=" + jarFile.getName())
.execute(gfshRule).getOutputText()).contains(jarFile.getName())
.contains("Un-Deployed From JAR Location");

assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list deployed")
.execute(gfshRule).getOutputText()).doesNotContain(jarFile.getName());
}

@Test
public void testUndeployWithNothingDeployed() {
assertThat(
GfshScript.of(getLocatorGFSHConnectionString(),
"undeploy --jar=" + jarFile.getName())
.execute(gfshRule).getOutputText()).contains(jarFile.getName() + " not deployed");
}

@Test
public void testRedeployNewJar() throws IOException {
GfshScript.of(getLocatorGFSHConnectionString(),
"deploy --jar=" + jarFile.getCanonicalPath()).execute(gfshRule);

assertThat(
GfshScript.of(getLocatorGFSHConnectionString(),
"undeploy --jar=" + jarFile.getName())
.execute(gfshRule).getOutputText()).contains(jarFile.getName())
.contains("Un-Deployed From JAR Location");

assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list deployed")
.execute(gfshRule).getOutputText()).doesNotContain(jarFile.getName());

GfshScript
.of(getLocatorGFSHConnectionString(),
"deploy --jar=" + anotherJarFile.getCanonicalPath())
.execute(gfshRule);
assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list deployed")
.execute(gfshRule).getOutputText()).contains(anotherJarFile.getName());
}

@Test
public void testUpdateJar() throws IOException {
GfshScript.of(getLocatorGFSHConnectionString(),
"deploy --jar=" + jarFile.getCanonicalPath()).execute(gfshRule);

GfshScript.of(getLocatorGFSHConnectionString(),
"deploy --jar=" + jarFileV2.getCanonicalPath()).execute(gfshRule);

assertThat(GfshScript.of(getLocatorGFSHConnectionString(),
"list deployed").execute(gfshRule).getOutputText()).contains(jarFileV2.getName())
.doesNotContain(jarFile.getName());
}

@Test
public void testDeployMultipleJars() throws IOException {
GfshScript.of(getLocatorGFSHConnectionString(),
"deploy --jar=" + jarFile.getCanonicalPath(),
"deploy --jar=" + anotherJarFile.getCanonicalPath()).execute(gfshRule);

assertThat(GfshScript.of(getLocatorGFSHConnectionString(),
"list deployed").execute(gfshRule).getOutputText()).contains(jarFile.getName())
.contains(anotherJarFile.getName());
}

@Test
public void testDeployFunction() throws IOException {
JarBuilder jarBuilder = new JarBuilder();
File source = loadTestResource("/example/test/function/ExampleFunction.java");

File outputJar = new File(stagingTempDir.newFolder(), "function.jar");
jarBuilder.buildJar(outputJar, source);

GfshScript.of(getLocatorGFSHConnectionString(), "deploy --jars=" + outputJar.getCanonicalPath())
.execute(gfshRule);

assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list functions").execute(gfshRule)
.getOutputText()).contains("ExampleFunction");

assertThat(
GfshScript.of(getLocatorGFSHConnectionString(), "execute function --id=ExampleFunction")
.execute(gfshRule)
.getOutputText()).contains("SUCCESS");
}

@Test
public void testDeployAndUndeployFunction() throws IOException {
JarBuilder jarBuilder = new JarBuilder();
File source = loadTestResource("/example/test/function/ExampleFunction.java");

File outputJar = new File(stagingTempDir.newFolder(), "function.jar");
jarBuilder.buildJar(outputJar, source);

GfshScript.of(getLocatorGFSHConnectionString(), "deploy --jars=" + outputJar.getCanonicalPath())
.execute(gfshRule);

assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list functions").execute(gfshRule)
.getOutputText()).contains("ExampleFunction");

assertThat(
GfshScript.of(getLocatorGFSHConnectionString(), "execute function --id=ExampleFunction")
.execute(gfshRule)
.getOutputText()).contains("SUCCESS");

GfshScript
.of(getLocatorGFSHConnectionString(), "undeploy --jars=" + outputJar.getName())
.execute(gfshRule);

assertThat(GfshScript.of(getLocatorGFSHConnectionString(), "list functions").execute(gfshRule)
.getOutputText()).doesNotContain("ExampleFunction");


}

@Test
public void testDeployPojo() throws IOException {
JarBuilder jarBuilder = new JarBuilder();
File functionSource = loadTestResource("/example/test/function/PojoFunction.java");
File pojoSource = loadTestResource("/example/test/pojo/ExamplePojo.java");

File outputJar = new File(stagingTempDir.newFolder(), "functionAndPojo.jar");
jarBuilder.buildJar(outputJar, pojoSource, functionSource);

System.out.println(GfshScript
.of(getLocatorGFSHConnectionString(),
"create disk-store --name=ExampleDiskStore --dir="
+ stagingTempDir.newFolder().getCanonicalPath())
.execute(gfshRule).getOutputText());

System.out.println(GfshScript
.of(getLocatorGFSHConnectionString(),
"create region --name=/ExampleRegion --type=REPLICATE_PERSISTENT --disk-store=ExampleDiskStore")
.execute(gfshRule).getOutputText());

System.out.println(GfshScript
.of(getLocatorGFSHConnectionString(), "deploy --jars=" + outputJar.getAbsolutePath())
.execute(gfshRule));

System.out.println(
GfshScript.of(getLocatorGFSHConnectionString(), "execute function --id=PojoFunction")
.execute(gfshRule).getOutputText());

assertThat(GfshScript
.of(getLocatorGFSHConnectionString(), "query --query=\"SELECT * FROM /ExampleRegion\"")
.execute(gfshRule).getOutputText()).contains("John");

GfshScript.of(getLocatorGFSHConnectionString(), "stop server --name=server").execute(gfshRule);

GfshScript.of(getLocatorGFSHConnectionString(),
"start server --name=server --locators=localhost[10334] --server-port=40404 --http-service-port=9090 --start-rest-api")
.execute(gfshRule);

assertThat(GfshScript
.of(getLocatorGFSHConnectionString(), "query --query=\"SELECT * FROM /ExampleRegion\"")
.execute(gfshRule).getOutputText()).contains("John");
}

private File loadTestResource(String fileName) {
String filePath =
createTempFileFromResource(this.getClass(), fileName).getAbsolutePath();
assertThat(filePath).isNotNull();

return new File(filePath);
}
}

0 comments on commit 9637ddd

Please sign in to comment.