Skip to content
Permalink
Browse files

Move Scheduler SPI into Deployer SPI

- Move the Scheduler interface into Deployer SPI
- Change the package from `org.spring.cloud.scheduler.spi` into `org.spring.cloud.deployer.scheduler.spi`
- Move related support classes, tests
- Resolves #313
  • Loading branch information
ilayaperumalg authored and jvalkeal committed Aug 14, 2019
1 parent 3fe396e commit d68f14dfbd7266dc08e97f8b3086ea91e049b050
Showing with 1,219 additions and 7 deletions.
  1. +1 −0 pom.xml
  2. +7 −0 spring-cloud-deployer-scheduler-spi-test-app/Dockerfile
  3. +64 −0 spring-cloud-deployer-scheduler-spi-test-app/pom.xml
  4. +83 −0 ...main/java/org/springframework/cloud/deployer/scheduler/spi/test/app/SchedulerIntegrationTest.java
  5. +34 −0 ...rg/springframework/cloud/deployer/scheduler/spi/test/app/SchedulerIntegrationTestApplication.java
  6. +132 −0 ...org/springframework/cloud/deployer/scheduler/spi/test/app/SchedulerIntegrationTestProperties.java
  7. +2 −0 spring-cloud-deployer-scheduler-spi-test-app/src/main/resources/application.properties
  8. +476 −0 ...java/org/springframework/cloud/deployer/scheduler/spi/test/AbstractSchedulerIntegrationTests.java
  9. +9 −7 ...c/main/java/org/springframework/cloud/deployer/spi/test/AbstractTaskLauncherIntegrationTests.java
  10. +30 −0 .../src/main/java/org/springframework/cloud/deployer/scheduler/spi/core/CreateScheduleException.java
  11. +92 −0 ...eployer-spi/src/main/java/org/springframework/cloud/deployer/scheduler/spi/core/ScheduleInfo.java
  12. +111 −0 ...oyer-spi/src/main/java/org/springframework/cloud/deployer/scheduler/spi/core/ScheduleRequest.java
  13. +72 −0 ...d-deployer-spi/src/main/java/org/springframework/cloud/deployer/scheduler/spi/core/Scheduler.java
  14. +34 −0 ...r-spi/src/main/java/org/springframework/cloud/deployer/scheduler/spi/core/SchedulerException.java
  15. +39 −0 ...pi/src/main/java/org/springframework/cloud/deployer/scheduler/spi/core/SchedulerPropertyKeys.java
  16. +33 −0 ...-spi/src/main/java/org/springframework/cloud/deployer/scheduler/spi/core/UnScheduleException.java
@@ -31,6 +31,7 @@
<module>spring-cloud-deployer-spi-test</module>
<module>spring-cloud-deployer-resource-support</module>
<module>spring-cloud-deployer-spi-test-app</module>
<module>spring-cloud-deployer-scheduler-spi-test-app</module>
<module>spring-cloud-deployer-autoconfigure</module>
<module>spring-cloud-deployer-dependencies</module>
</modules>
@@ -0,0 +1,7 @@
FROM java:8-alpine

ARG JAR_FILE

ADD target/${JAR_FILE} spring-cloud-deployer-scheduler-spi-test-app.jar

ENTRYPOINT ["java", "-jar", "/spring-cloud-deployer-scheduler-spi-test-app.jar"]
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-deployer-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-cloud-deployer-scheduler-spi-test-app</artifactId>
<properties>
<start-class>org.springframework.cloud.deployer.scheduler.spi.test.app.SchedulerIntegrationTestApplication</start-class>
<java.version>1.8</java.version>
<docker.image.prefix>springcloud</docker.image.prefix>
<dockerfile-maven-plugin.version>1.3.6</dockerfile-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<!--optional so that it does its job while compiling, but is not included in
the resulting artifact -->
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-plugin.version}</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<tag>${project.version}</tag>
<tag>latest</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}-exec.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,83 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.cloud.deployer.scheduler.spi.test.app;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

import static org.springframework.cloud.deployer.scheduler.spi.test.app.SchedulerIntegrationTestProperties.FUNNY_CHARACTERS;

/**
* An app that can misbehave, useful for integration testing of app deployers.
*
* @author Glenn Renfro
* @author Ilayaperumal Gopinathan
*/
@EnableConfigurationProperties(SchedulerIntegrationTestProperties.class)
@Configuration
public class SchedulerIntegrationTest {

protected final Logger log = LoggerFactory.getLogger(this.getClass());

@Autowired
private SchedulerIntegrationTestProperties properties;

@PostConstruct
public void init() throws InterruptedException {
String parameterThatMayNeedEscaping = properties.getParameterThatMayNeedEscaping();
if (parameterThatMayNeedEscaping != null && !FUNNY_CHARACTERS.equals(parameterThatMayNeedEscaping)) {
throw new IllegalArgumentException(String.format("Expected 'parameterThatMayNeedEscaping' value to be equal to '%s', but was '%s'", FUNNY_CHARACTERS, parameterThatMayNeedEscaping));
}

String commandLineArgValueThatMayNeedEscaping = properties.getCommandLineArgValueThatMayNeedEscaping();
if (commandLineArgValueThatMayNeedEscaping != null && !FUNNY_CHARACTERS.equals(commandLineArgValueThatMayNeedEscaping)) {
throw new IllegalArgumentException(String.format("Expected 'commandLineArgValueThatMayNeedEscaping' value to be equal to '%s', but was '%s'", FUNNY_CHARACTERS, commandLineArgValueThatMayNeedEscaping));
}

Assert.notNull(properties.getInstanceIndex(), "instanceIndex should have been set by deployer or runtime");

if (properties.getMatchInstances().isEmpty() || properties.getMatchInstances().contains(properties.getInstanceIndex())) {
log.info("Waiting for %dms before allowing further initialization and actuator startup...", properties.getInitDelay());
Thread.sleep(properties.getInitDelay());
log.info("... done");
if (properties.getKillDelay() >= 0) {
log.info("Will kill this process in %dms%n", properties.getKillDelay());
new Thread() {

@Override
public void run() {
try {
Thread.sleep(properties.getKillDelay());
System.exit(properties.getExitCode());
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}.start();
}
}
}

}
@@ -0,0 +1,34 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.cloud.deployer.scheduler.spi.test.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Main application runner. Will keep the main method running, to simulate a long running process.
*
* @author Glenn Renfro
* @author Ilayaperumal Gopinathan
*/
@SpringBootApplication
public class SchedulerIntegrationTestApplication {

public static void main(String[] args) {
SpringApplication.run(SchedulerIntegrationTestApplication.class, args);
}
}
@@ -0,0 +1,132 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.cloud.deployer.scheduler.spi.test.app;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* Configuration properties for the IntegrationTestProcessor app.
*
* @author Glenn Renfro
* @author Ilayaperumal Gopinathan
*/
@ConfigurationProperties
public class SchedulerIntegrationTestProperties {

public static final String FUNNY_CHARACTERS = "&'\"|< é\\(";

/**
* The delay in milliseconds to stall the initialization of this app.
* Useful for testing the 'deploying' state of a app.
*/
private int initDelay = 0;

/**
* The delay in milliseconds after which this app will kill itself.
* <p>-1 means don't kill</p>
*/
private int killDelay = -1;

/**
* The exit code used when this app will kill itself.
* <p>Set this to 0 for normal exit</p>
*/
private int exitCode = 1;

/**
* If not empty, only the app intances whose number(s) are contained in this set
* will behave according to the other configuration parameters.
*/
private Set<Integer> matchInstances = new HashSet<>();

/**
* If not null, this property will be tested against {@link #FUNNY_CHARACTERS}.
* This makes sure that a deployer knows how to properly propagate application properties, including
* those that contain chars that often require some form of escaping.
*/
private String parameterThatMayNeedEscaping;

/**
* If not null, this property will be tested against {@link #FUNNY_CHARACTERS}.
* This makes sure that a deployer knows how to properly propagate deployment properties, including
* those that contain chars that often require some form of escaping.
*/
private String commandLineArgValueThatMayNeedEscaping;

@Value("${INSTANCE_INDEX:${CF_INSTANCE_INDEX:0}}")
private Integer instanceIndex;

public int getInitDelay() {
return initDelay;
}

public void setInitDelay(int initDelay) {
this.initDelay = initDelay;
}

public int getKillDelay() {
return killDelay;
}

public void setKillDelay(int killDelay) {
this.killDelay = killDelay;
}

public int getExitCode() {
return exitCode;
}

public void setExitCode(int exitCode) {
this.exitCode = exitCode;
}

public Set<Integer> getMatchInstances() {
return matchInstances;
}

public void setMatchInstances(Set<Integer> matchInstances) {
this.matchInstances = matchInstances;
}

public String getParameterThatMayNeedEscaping() {
return parameterThatMayNeedEscaping;
}

public void setParameterThatMayNeedEscaping(String parameterThatMayNeedEscaping) {
this.parameterThatMayNeedEscaping = parameterThatMayNeedEscaping;
}

public Integer getInstanceIndex() {
return instanceIndex;
}

public void setInstanceIndex(Integer instanceIndex) {
this.instanceIndex = instanceIndex;
}

public String getCommandLineArgValueThatMayNeedEscaping() {
return commandLineArgValueThatMayNeedEscaping;
}

public void setCommandLineArgValueThatMayNeedEscaping(String commandLineArgValueThatMayNeedEscaping) {
this.commandLineArgValueThatMayNeedEscaping = commandLineArgValueThatMayNeedEscaping;
}
}
@@ -0,0 +1,2 @@
management.endpoint.shutdown.enabled=true
management.endpoints.web.exposure.include=*

0 comments on commit d68f14d

Please sign in to comment.
You can’t perform that action at this time.