Commit 1769d843 authored by Michael Ritter's avatar Michael Ritter
Browse files

Spring boot 2.1

parent 8eb49022
......@@ -12,6 +12,7 @@
<version>3.1.0-SNAPSHOT</version>
<name>Common</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
......
......@@ -25,7 +25,7 @@ public class TrackingThreadPoolExecutor<T> extends ThreadPoolExecutor {
private final Logger log = LoggerFactory.getLogger(TrackingThreadPoolExecutor.class);
// List of items we're working on
private Set<T> items = new ConcurrentSkipListSet<>();
private final Set<T> items = new ConcurrentSkipListSet<>();
public TrackingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
......@@ -81,7 +81,7 @@ public class TrackingThreadPoolExecutor<T> extends ThreadPoolExecutor {
public class Task extends FutureTask<T> {
// We want to be able to use this without super.call
private T result;
private final T result;
public Task(Runnable runnable, T result) {
super(runnable, result);
......
......@@ -97,7 +97,7 @@ public class MailUtil {
*/
public void send(final SimpleMailMessage message) {
if (smtpSend) {
log.info("Sending mail to {}", message.getTo());
log.info("Sending mail to {}", new Object[]{message.getTo()});
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost(smtpHost);
sender.send(message);
......
......@@ -3,17 +3,19 @@ package org.chronopolis.common.storage;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import javax.annotation.Nullable;
/**
* @author shake
*/
public class BagStagingPropertiesValidator implements Validator {
@Override
public boolean supports(Class<?> clazz) {
public boolean supports(@Nullable Class<?> clazz) {
return BagStagingProperties.class == clazz;
}
@Override
public void validate(Object target, Errors errors) {
public void validate(@Nullable Object target, @Nullable Errors errors) {
PosixValidator validator = new PosixValidator();
BagStagingProperties properties = (BagStagingProperties) target;
if (properties.getPosix() == null) {
......
......@@ -3,6 +3,7 @@ package org.chronopolis.common.storage;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import javax.annotation.Nullable;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
......@@ -19,12 +20,12 @@ import java.nio.file.Paths;
*/
public class PosixValidator implements Validator {
@Override
public boolean supports(Class<?> clazz) {
public boolean supports(@Nullable Class<?> clazz) {
return Posix.class == clazz;
}
@Override
public void validate(Object target, Errors errors) {
public void validate(@Nullable Object target, @Nullable Errors errors) {
Posix posix = (Posix) target;
if (posix.getPath() != null) {
......
......@@ -3,18 +3,20 @@ package org.chronopolis.common.storage;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import javax.annotation.Nullable;
/**
* @author shake
*/
public class PreservationPropertiesValidator implements Validator {
@Override
public boolean supports(Class<?> clazz) {
public boolean supports(@Nullable Class<?> clazz) {
return PreservationProperties.class == clazz;
}
@Override
public void validate(Object target, Errors errors) {
public void validate(@Nullable Object target, @Nullable Errors errors) {
PosixValidator posixValidator = new PosixValidator();
PreservationProperties properties = (PreservationProperties) target;
if (properties.getPosix().isEmpty()) {
......
......@@ -2,6 +2,7 @@ package org.chronopolis.common.storage;
import com.google.common.collect.ComparisonChain;
import javax.annotation.Nullable;
import java.nio.file.Path;
/**
......@@ -75,7 +76,7 @@ public abstract class StorageOperation implements Comparable<StorageOperation> {
}
@Override
public int compareTo(StorageOperation operation) {
public int compareTo(@Nullable StorageOperation operation) {
return ComparisonChain.start()
.compare(this.size, operation.size)
.compare(this.type, operation.type)
......
......@@ -3,17 +3,19 @@ package org.chronopolis.common.storage;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import javax.annotation.Nullable;
/**
* @author shake
*/
public class TokenStagingPropertiesValidator implements Validator {
@Override
public boolean supports(Class<?> clazz) {
public boolean supports(@Nullable Class<?> clazz) {
return TokenStagingProperties.class == clazz;
}
@Override
public void validate(Object target, Errors errors) {
public void validate(@Nullable Object target, @Nullable Errors errors) {
PosixValidator validator = new PosixValidator();
TokenStagingProperties properties = (TokenStagingProperties) target;
if (properties.getPosix() == null) {
......
......@@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
public class TrackingThreadPoolExecutorTest {
@Test
public void testExceptionInRunnable() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
public void testExceptionInRunnable() throws InterruptedException {
TrackingThreadPoolExecutor<Integer> threadPoolExecutor = new TrackingThreadPoolExecutor<>(4,
4,
5,
......@@ -32,7 +32,7 @@ public class TrackingThreadPoolExecutorTest {
}
@Test
public void testRejected() throws NoSuchFieldException, IllegalAccessException {
public void testRejected() {
TrackingThreadPoolExecutor<Integer> threadPoolExecutor = new TrackingThreadPoolExecutor<>(1,
1,
5,
......
......@@ -4,7 +4,7 @@ import org.assertj.core.util.Files;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.util.Assert;
......@@ -23,9 +23,11 @@ public class PosixValidatorTest {
public void bindValid() {
context.register(SamplePropertyApplication.class);
File tmp = Files.temporaryFolder();
EnvironmentTestUtils.addEnvironment(context,
TestPropertyValues.of(
"storage.preservation.posix[0].id:1",
"storage.preservation.posix[0].path:" + tmp.toString());
"storage.preservation.posix[0].path:" + tmp.toString()
).applyTo(context);
context.refresh();
PreservationProperties properties = context.getBean(PreservationProperties.class);
......@@ -35,14 +37,17 @@ public class PosixValidatorTest {
@Test(expected = BeanCreationException.class)
public void bindInvalid() {
context.register(SamplePropertyApplication.class);
EnvironmentTestUtils.addEnvironment(context, "storage.preservation.posix[0].id:1", "storage.preservation.posix[0].path:/dne");
TestPropertyValues.of(
"storage.preservation.posix[0].id:1",
"storage.preservation.posix[0].path:/dne"
).applyTo(context);
context.refresh();
}
@Test(expected = BeanCreationException.class)
public void bindNoProperties() {
context.register(SamplePropertyApplication.class);
EnvironmentTestUtils.addEnvironment(context);
TestPropertyValues.of().applyTo(context);
context.refresh();
}
......
......@@ -28,7 +28,7 @@ public class SamplePropertyApplication implements CommandLineRunner{
}
@Override
public void run(String... args) throws Exception {
public void run(String... args) {
for (Posix posix : preservationProperties.getPosix()) {
System.out.println("==================================");
System.out.println("Posix Ingest Id: " + posix.getId());
......
......@@ -99,11 +99,7 @@
</build>
<properties>
<flyway.version>4.2.0</flyway.version>
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
<thymeleaf-extras-springsecurity4.version>3.0.2.RELEASE
</thymeleaf-extras-springsecurity4.version>
</properties>
<dependencies>
......@@ -154,7 +150,7 @@
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
......
......@@ -2,7 +2,7 @@
rpmdir=$PWD
sources=SOURCES
finaljar=$sources/ingest-server.jar
finaljar=${sources}/ingest-server.jar
retval=0
if [ "$1" = "clean" ]; then
......@@ -16,8 +16,8 @@ if [ "$1" = "clean" ]; then
exit 0
fi
if [ ! -d $sources ]; then
mkdir $sources
if [ ! -d ${sources} ]; then
mkdir ${sources}
fi
cd ../
......@@ -30,12 +30,12 @@ if [ $? -ne 0 ]; then
exit -1
fi
version=`echo $full_version | sed 's/-.*//'`
release_type=`echo $full_version | sed 's/.*-//'`
version=`echo ${full_version} | sed 's/-.*//'`
release_type=`echo ${full_version} | sed 's/.*-//'`
jarfile=target/ingest-rest-$version-$release_type.jar
jarfile=target/ingest-rest-${version}-${release_type}.jar
if [ ! -e $jarfile ]; then
if [ ! -e ${jarfile} ]; then
echo "Building latest jar..."
# todo: profile should be an env var
mvn -q -Dmaven.test.redirectTestOutputToFile=true -Dspring.profiles.active=gitlab clean install # > /dev/null
......@@ -49,13 +49,13 @@ fi
# Copy the artifacts
cp $jarfile rpm/$finaljar
cp target/classes/application.yml rpm/$sources
cp src/main/sh/ingest-server.sh rpm/$sources
cp src/main/sh/ingest-prepare.sh rpm/$sources
cp src/main/sh/ingest-server.service rpm/$sources
cp ${jarfile} rpm/${finaljar}
cp target/classes/application.yml rpm/${sources}
cp src/main/sh/ingest-server.sh rpm/${sources}
cp src/main/sh/ingest-prepare.sh rpm/${sources}
cp src/main/sh/ingest-server.service rpm/${sources}
# cd back to where we started and build the rpm
cd $rpmdir
cd ${rpmdir}
rpmbuild -ba --define="_topdir $PWD" --define="_tmppath $PWD/tmp" --define="ver $version" SPECS/ingest-server-el6.spec
rpmbuild -ba --define="_topdir $PWD" --define="_tmppath $PWD/tmp" --define="ver $version" SPECS/ingest-server-el7.spec
package db.migration;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
......@@ -11,15 +12,16 @@ import java.sql.ResultSet;
/**
* Migration to encode our users' passwords with bcrypt
*
* <p>
* Created by shake on 9/7/16.
*/
public class V1_4__Bcrypt implements JdbcMigration {
public class V1_4__Bcrypt extends BaseJavaMigration {
private final String update = "UPDATE users SET password = ? WHERE username = ?";
private final Logger log = LoggerFactory.getLogger(V1_4__Bcrypt.class);
@Override
public void migrate(Connection connection) throws Exception {
public void migrate(Context context) throws Exception {
Connection connection = context.getConnection();
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
PreparedStatement ps = connection.prepareStatement("SELECT username, password FROM users");
......
package db.migration;
import org.chronopolis.rest.models.enums.DataType;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -15,11 +16,12 @@ import java.sql.ResultSet;
*
* Created by shake on 7/12/17.
*/
public class V1_6_01__Default_storage_regions implements JdbcMigration {
public class V1_6_01__Default_storage_regions extends BaseJavaMigration {
private final Logger log = LoggerFactory.getLogger(V1_6_01__Default_storage_regions.class);
@Override
public void migrate(Connection connection) throws Exception {
public void migrate(Context context) throws Exception {
Connection connection = context.getConnection();
long numBags = 0;
boolean created = false;
String count = "SELECT count(id) FROM bag";
......@@ -38,7 +40,7 @@ public class V1_6_01__Default_storage_regions implements JdbcMigration {
log.info("Bag count is {}", numBags);
}
// If no nodes exist and no bags exist, this should do nothing
// If no nodes exist and no bags exist, this should do nothing
while (nodeSet.next()) {
created = true;
long id = nodeSet.getLong(1);
......@@ -60,5 +62,4 @@ public class V1_6_01__Default_storage_regions implements JdbcMigration {
}
}
}
}
package db.migration;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -12,14 +13,15 @@ import java.sql.Statement;
/**
* Create storage entries for each bag
*
* <p>
* Created by shake on 7/13/17.
*/
public class V1_6_03__Bag_storage_entries implements JdbcMigration {
public class V1_6_03__Bag_storage_entries extends BaseJavaMigration {
private final Logger log = LoggerFactory.getLogger(V1_6_03__Bag_storage_entries.class);
@Override
public void migrate(Connection connection) throws Exception {
public void migrate(Context context) throws Exception {
Connection connection = context.getConnection();
String sqlSelectBags = "SELECT id, location, tag_manifest_digest, token_location, token_digest, size, total_files, fixity_algorithm FROM bag";
String sqlSelectBagRegion = "SELECT id FROM storage_region WHERE data_type = 'BAG'";
String sqlSelectTokenRegion = "SELECT id FROM storage_region WHERE data_type = 'TOKEN'";
......
......@@ -12,7 +12,7 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.system.ApplicationPidFileWriter;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.context.annotation.ComponentScan;
/**
......@@ -48,7 +48,7 @@ public class Application implements CommandLineRunner {
}
@Override
public void run(final String... args) throws Exception {
public void run(final String... args) {
service.runServer();
}
......
......@@ -78,7 +78,7 @@ public class IngestController {
String order = params.getOrDefault(SORT_DIRECTION, "asc");
Sort.Direction direction = Sort.Direction.fromString(order);
return new PageRequest(pageNum, pageSize, direction, pList);
return PageRequest.of(pageNum, pageSize, direction, pList);
}
}
......@@ -15,7 +15,7 @@ public class PageWrapper<T> {
private static final int MAX_SIZE = 5;
private List<Integer> pages;
private final List<Integer> pages;
private boolean firstParam = true;
private String url;
......
......@@ -47,9 +47,9 @@ import org.chronopolis.rest.models.serializers.ZonedDateTimeDeserializer;
import org.chronopolis.rest.models.serializers.ZonedDateTimeSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
......@@ -123,11 +123,11 @@ public class IngestConfig {
}
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory(IngestProperties properties) {
public ServletWebServerFactory embeddedServletContainerFactory(IngestProperties properties) {
IngestProperties.Ajp ajp = properties.getAjp();
String AJP_SCHEME = "http";
String AJP_PROTOCOL = "AJP/1.3";
TomcatEmbeddedServletContainerFactory bean = new TomcatEmbeddedServletContainerFactory();
TomcatServletWebServerFactory bean = new TomcatServletWebServerFactory();
if (ajp.isEnabled()) {
log.info("Setting up ajp connector");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment