diff --git a/cache-updater/application.properties b/cache-updater/application.properties
new file mode 100644
index 0000000000..8bfa1c2542
--- /dev/null
+++ b/cache-updater/application.properties
@@ -0,0 +1,7 @@
+jdbc.url=jdbc:mysql://192.168.1.2:3306/cache
+jdbc.username=runelite
+jdbc.password=runelite
+minio.url=http://192.168.1.2:9000
+minio.accesskey=QPQ15JX1ESAVMR0TLCL1
+minio.secretkey=
+minio.bucket=runelite
\ No newline at end of file
diff --git a/cache-updater/pom.xml b/cache-updater/pom.xml
new file mode 100644
index 0000000000..7489d39ff8
--- /dev/null
+++ b/cache-updater/pom.xml
@@ -0,0 +1,105 @@
+
+
+
+ 4.0.0
+
+ net.runelite
+ runelite-parent
+ 1.2.15-SNAPSHOT
+
+
+ Cache Updater
+ cache-updater
+
+
+ 1.5.6.RELEASE
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+ ${spring.boot.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+ ${spring.boot.version}
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ ${spring.boot.version}
+ true
+
+
+ mysql
+ mysql-connector-java
+ 5.1.45
+
+
+ net.runelite
+ cache-client
+ ${project.version}
+
+
+ org.sql2o
+ sql2o
+ 1.5.4
+
+
+ io.minio
+ minio
+ 3.0.6
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${spring.boot.version}
+
+
+
+ repackage
+
+
+ spring-boot
+ net.runelite.cache.updater.CacheUpdater
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/http-service/src/main/resources/net/runelite/http/service/cache/schema.sql b/cache-updater/schema.sql
similarity index 100%
rename from http-service/src/main/resources/net/runelite/http/service/cache/schema.sql
rename to cache-updater/schema.sql
diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java
new file mode 100644
index 0000000000..354ca0b394
--- /dev/null
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2018, Adam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.runelite.cache.updater;
+
+import io.minio.MinioClient;
+import io.minio.errors.InvalidEndpointException;
+import io.minio.errors.InvalidPortException;
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
+import javax.sql.DataSource;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.sql2o.Sql2o;
+import org.sql2o.converters.Converter;
+import org.sql2o.quirks.NoQuirks;
+
+@Configuration
+public class CacheConfiguration
+{
+ @Value("${jdbc.url}")
+ private String jdbcUrl;
+
+ @Value("${jdbc.username}")
+ private String jdbcUsername;
+
+ @Value("${jdbc.password}")
+ private String jdbcPassword;
+
+ @Value("${minio.url}")
+ private String minioUrl;
+
+ @Value("${minio.accesskey}")
+ private String minioAccessKey;
+
+ @Value("${minio.secretkey}")
+ private String minioSecretKey;
+
+ @Bean
+ public DataSource dataSource()
+ {
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setUrl(jdbcUrl);
+ dataSource.setUsername(jdbcUsername);
+ dataSource.setPassword(jdbcPassword);
+ return dataSource;
+ }
+
+ @Bean
+ @Qualifier("Runelite Cache SQL2O")
+ public Sql2o sql2o(DataSource dataSource)
+ {
+ Map converters = new HashMap<>();
+ converters.put(Instant.class, new InstantConverter());
+ return new Sql2o(dataSource, new NoQuirks(converters));
+ }
+
+ @Bean
+ public MinioClient minioClient() throws InvalidEndpointException, InvalidPortException
+ {
+ return new MinioClient(minioUrl, minioAccessKey, minioSecretKey);
+ }
+}
diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java
new file mode 100644
index 0000000000..2834e5bb1e
--- /dev/null
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2017, Adam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.runelite.cache.updater;
+
+import java.time.Instant;
+import java.util.List;
+import net.runelite.cache.updater.beans.ArchiveEntry;
+import net.runelite.cache.updater.beans.CacheEntry;
+import net.runelite.cache.updater.beans.IndexEntry;
+import org.sql2o.Connection;
+import org.sql2o.Query;
+import org.sql2o.ResultSetIterable;
+
+class CacheDAO
+{
+ // cache prepared statements for high volume queries
+ private Query associateArchive;
+ private Query findArchive, insertArchive;
+ private Query associateFile;
+
+ public CacheEntry findMostRecent(Connection con)
+ {
+ return con.createQuery("select id, revision, date from cache order by revision desc, date desc limit 1")
+ .executeAndFetchFirst(CacheEntry.class);
+ }
+
+ public List findIndexesForCache(Connection con, CacheEntry cache)
+ {
+ return con.createQuery("select id, indexId, crc, revision from `index` where cache = :cache")
+ .addParameter("cache", cache.getId())
+ .executeAndFetch(IndexEntry.class);
+ }
+
+ public ResultSetIterable findArchivesForIndex(Connection con, IndexEntry indexEntry)
+ {
+ return con.createQuery("select archive.id, archive.archiveId, archive.nameHash,"
+ + " archive.crc, archive.revision, archive.hash from index_archive "
+ + "join archive on index_archive.archive = archive.id "
+ + "where index_archive.index = :id")
+ .addParameter("id", indexEntry.getId())
+ .executeAndFetchLazy(ArchiveEntry.class);
+ }
+
+ public CacheEntry createCache(Connection con, int revision, Instant date)
+ {
+ int cacheId = con.createQuery("insert into cache (revision, date) values (:revision, :date)")
+ .addParameter("revision", revision)
+ .addParameter("date", date)
+ .executeUpdate()
+ .getKey(int.class);
+
+ CacheEntry entry = new CacheEntry();
+ entry.setId(cacheId);
+ entry.setRevision(revision);
+ entry.setDate(date);
+ return entry;
+ }
+
+ public IndexEntry createIndex(Connection con, CacheEntry cache, int indexId, int crc, int revision)
+ {
+ int id = con.createQuery("insert into `index` (cache, indexId, crc, revision) values (:cache, :indexId, :crc, :revision)")
+ .addParameter("cache", cache.getId())
+ .addParameter("indexId", indexId)
+ .addParameter("crc", crc)
+ .addParameter("revision", revision)
+ .executeUpdate()
+ .getKey(int.class);
+
+ IndexEntry entry = new IndexEntry();
+ entry.setId(id);
+ entry.setIndexId(indexId);
+ entry.setCrc(crc);
+ entry.setRevision(revision);
+ return entry;
+ }
+
+ public void associateArchiveToIndex(Connection con, ArchiveEntry archive, IndexEntry index)
+ {
+ if (associateArchive == null)
+ {
+ associateArchive = con.createQuery("insert into index_archive (`index`, archive) values (:index, :archive)");
+ }
+ associateArchive
+ .addParameter("index", index.getId())
+ .addParameter("archive", archive.getId())
+ .executeUpdate();
+ }
+
+ public ArchiveEntry findArchive(Connection con, IndexEntry index,
+ int archiveId, int nameHash, int crc, int revision)
+ {
+ if (findArchive == null)
+ {
+ findArchive = con.createQuery("select distinct archive.id, archive.archiveId, archive.nameHash,"
+ + " archive.crc, archive.revision, archive.hash from archive "
+ + " join index_archive on index_archive.archive = archive.id"
+ + " join `index` on index.id = index_archive.index"
+ + " where archive.archiveId = :archiveId"
+ + " and archive.nameHash = :nameHash"
+ + " and archive.crc = :crc"
+ + " and archive.revision = :revision"
+ + " and index.indexId = :indexId");
+ }
+
+ ArchiveEntry entry = findArchive
+ .addParameter("archiveId", archiveId)
+ .addParameter("nameHash", nameHash)
+ .addParameter("crc", crc)
+ .addParameter("revision", revision)
+ .addParameter("indexId", index.getIndexId())
+ .executeAndFetchFirst(ArchiveEntry.class);
+ return entry;
+ }
+
+ public ArchiveEntry createArchive(Connection con, IndexEntry index,
+ int archiveId, int nameHash, int crc, int revision, byte[] hash)
+ {
+ if (insertArchive == null)
+ {
+ insertArchive = con.createQuery("insert into archive (archiveId, nameHash, crc, revision, hash) values "
+ + "(:archiveId, :nameHash, :crc, :revision, :hash)");
+ }
+
+ int id = insertArchive
+ .addParameter("archiveId", archiveId)
+ .addParameter("nameHash", nameHash)
+ .addParameter("crc", crc)
+ .addParameter("revision", revision)
+ .addParameter("hash", hash)
+ .executeUpdate()
+ .getKey(int.class);
+
+ ArchiveEntry entry = new ArchiveEntry();
+ entry.setId(id);
+ entry.setArchiveId(archiveId);
+ entry.setNameHash(nameHash);
+ entry.setCrc(crc);
+ entry.setRevision(revision);
+ entry.setHash(hash);
+ return entry;
+ }
+
+ public void associateFileToArchive(Connection con, ArchiveEntry archive, int fileId, int nameHash)
+ {
+ if (associateFile == null)
+ {
+ associateFile = con.createQuery("insert into file (archive, fileId, nameHash) values (:archive, :fileId, :nameHash)");
+ }
+ associateFile
+ .addParameter("archive", archive.getId())
+ .addParameter("fileId", fileId)
+ .addParameter("nameHash", nameHash)
+ .executeUpdate();
+ }
+}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheStorage.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheStorage.java
similarity index 95%
rename from http-service/src/main/java/net/runelite/http/service/cache/CacheStorage.java
rename to cache-updater/src/main/java/net/runelite/cache/updater/CacheStorage.java
index fa4a90da2a..5a82b9c414 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/CacheStorage.java
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/CacheStorage.java
@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package net.runelite.http.service.cache;
+package net.runelite.cache.updater;
import java.io.IOException;
import java.util.List;
@@ -32,9 +32,9 @@ import net.runelite.cache.fs.Index;
import net.runelite.cache.fs.Storage;
import net.runelite.cache.fs.Store;
import net.runelite.cache.index.FileData;
-import net.runelite.http.service.cache.beans.ArchiveEntry;
-import net.runelite.http.service.cache.beans.CacheEntry;
-import net.runelite.http.service.cache.beans.IndexEntry;
+import net.runelite.cache.updater.beans.ArchiveEntry;
+import net.runelite.cache.updater.beans.CacheEntry;
+import net.runelite.cache.updater.beans.IndexEntry;
import org.sql2o.Connection;
import org.sql2o.ResultSetIterable;
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheUpdater.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheUpdater.java
similarity index 86%
rename from http-service/src/main/java/net/runelite/http/service/cache/CacheUpdater.java
rename to cache-updater/src/main/java/net/runelite/cache/updater/CacheUpdater.java
index 8f75f95f64..1a8f81c5ec 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/CacheUpdater.java
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/CacheUpdater.java
@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package net.runelite.http.service.cache;
+package net.runelite.cache.updater;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
@@ -37,29 +37,29 @@ import net.runelite.cache.client.CacheClient;
import net.runelite.cache.client.IndexInfo;
import net.runelite.cache.fs.Archive;
import net.runelite.cache.fs.Store;
+import net.runelite.cache.updater.beans.CacheEntry;
+import net.runelite.cache.updater.beans.IndexEntry;
import net.runelite.http.api.RuneLiteAPI;
-import net.runelite.http.service.cache.beans.CacheEntry;
-import net.runelite.http.service.cache.beans.IndexEntry;
import net.runelite.protocol.api.login.HandshakeResponseType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.sql2o.Connection;
import org.sql2o.Sql2o;
-@RestController
-@RequestMapping("/cache/admin")
-public class CacheUpdater
+@SpringBootApplication
+public class CacheUpdater implements CommandLineRunner
{
private static final Logger logger = LoggerFactory.getLogger(CacheUpdater.class);
private final Sql2o sql2o;
private final MinioClient minioClient;
-
+
@Value("${minio.bucket}")
private String minioBucket;
@@ -73,8 +73,7 @@ public class CacheUpdater
this.minioClient = minioClient;
}
- @RequestMapping("/update")
- public void check() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException
+ public void update() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException
{
int rsVersion = RuneLiteAPI.getRsVersion();
@@ -103,7 +102,8 @@ public class CacheUpdater
if (result != HandshakeResponseType.RESPONSE_OK)
{
- throw new OutOfDateException();
+ logger.warn("Out of date!");
+ return;
}
List indexes = client.requestIndexes();
@@ -158,4 +158,16 @@ public class CacheUpdater
return false;
}
+ @Override
+ public void run(String... args) throws Exception
+ {
+ update();
+ }
+
+ public static void main(String[] args)
+ {
+ SpringApplication.run(CacheUpdater.class, args).close();
+ System.exit(0);
+ }
+
}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheUploader.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheUploader.java
similarity index 98%
rename from http-service/src/main/java/net/runelite/http/service/cache/CacheUploader.java
rename to cache-updater/src/main/java/net/runelite/cache/updater/CacheUploader.java
index cea25cfd08..baad6971e0 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/CacheUploader.java
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/CacheUploader.java
@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package net.runelite.http.service.cache;
+package net.runelite.cache.updater;
import com.google.common.hash.Hashing;
import com.google.common.io.BaseEncoding;
diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java b/cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java
new file mode 100644
index 0000000000..953fe9bd3a
--- /dev/null
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017, Adam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.runelite.cache.updater;
+
+import java.sql.Timestamp;
+import java.time.Instant;
+import org.sql2o.converters.Converter;
+import org.sql2o.converters.ConverterException;
+
+public class InstantConverter implements Converter
+{
+ @Override
+ public Instant convert(Object val) throws ConverterException
+ {
+ Timestamp ts = (Timestamp) val;
+ return ts.toInstant();
+ }
+
+ @Override
+ public Object toDatabaseParam(Instant val)
+ {
+ return Timestamp.from(val);
+ }
+
+}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheSecurity.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/ArchiveEntry.java
similarity index 51%
rename from http-service/src/main/java/net/runelite/http/service/cache/CacheSecurity.java
rename to cache-updater/src/main/java/net/runelite/cache/updater/beans/ArchiveEntry.java
index dda373bfc6..9bacab75b8 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/CacheSecurity.java
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/beans/ArchiveEntry.java
@@ -22,45 +22,17 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package net.runelite.http.service.cache;
+package net.runelite.cache.updater.beans;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.Order;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import lombok.Data;
-@Configuration
-@EnableWebSecurity
-@Order(200)
-public class CacheSecurity extends WebSecurityConfigurerAdapter
+@Data
+public class ArchiveEntry
{
- @Value("${auth.password}")
- private String password;
-
- @Override
- protected void configure(HttpSecurity http) throws Exception
- {
- // By default spring security adds headers to not cache anything
- http.headers().cacheControl().disable();
-
- http.csrf().disable();
-
- http.httpBasic()
- .and()
- .authorizeRequests()
- .antMatchers("/cache/admin/**")
- .hasRole("ADMIN");
- }
-
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception
- {
- auth.inMemoryAuthentication()
- .withUser("admin")
- .password(password)
- .roles("ADMIN");
- }
+ private int id;
+ private int archiveId;
+ private int nameHash;
+ private int crc;
+ private int revision;
+ private byte[] hash;
}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/OutOfDateException.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/CacheEntry.java
similarity index 87%
rename from http-service/src/main/java/net/runelite/http/service/cache/OutOfDateException.java
rename to cache-updater/src/main/java/net/runelite/cache/updater/beans/CacheEntry.java
index e3c4d7b32c..c9081cd883 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/OutOfDateException.java
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/beans/CacheEntry.java
@@ -22,12 +22,15 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package net.runelite.http.service.cache;
+package net.runelite.cache.updater.beans;
-import org.springframework.web.bind.annotation.ResponseStatus;
+import java.time.Instant;
+import lombok.Data;
-@ResponseStatus(reason = "Out of date")
-public class OutOfDateException extends RuntimeException
+@Data
+public class CacheEntry
{
-
+ private int id;
+ private int revision;
+ private Instant date;
}
diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java
new file mode 100644
index 0000000000..bb43c2a189
--- /dev/null
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017, Adam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.runelite.cache.updater.beans;
+
+import lombok.Data;
+
+@Data
+public class FileEntry
+{
+ private int id;
+ private int archiveId;
+ private int fileId;
+ private int nameHash;
+}
diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java
new file mode 100644
index 0000000000..a5a0748f18
--- /dev/null
+++ b/cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017, Adam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.runelite.cache.updater.beans;
+
+import lombok.Data;
+
+@Data
+public class IndexEntry
+{
+ private int id;
+ private int indexId;
+ private int crc;
+ private int revision;
+}
diff --git a/http-service/pom.xml b/http-service/pom.xml
index 4f05e5af56..2c6b774b99 100644
--- a/http-service/pom.xml
+++ b/http-service/pom.xml
@@ -52,11 +52,6 @@
${spring.boot.version}
provided
-
- org.springframework.boot
- spring-boot-starter-security
- ${spring.boot.version}
-
org.springframework.boot
spring-boot-devtools
@@ -85,11 +80,6 @@
cache
${project.version}
-
- net.runelite
- cache-client
- ${project.version}
-
org.sql2o
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java b/http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java
index d9d4286f6f..08282ca38e 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java
+++ b/http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java
@@ -24,7 +24,6 @@
*/
package net.runelite.http.service.cache;
-import java.time.Instant;
import java.util.List;
import net.runelite.cache.IndexType;
import net.runelite.http.service.cache.beans.ArchiveEntry;
@@ -37,12 +36,6 @@ import org.sql2o.ResultSetIterable;
class CacheDAO
{
- // cache prepared statements for high volume queries
- private Query associateArchive;
- private Query findArchive, insertArchive;
- private Query associateFile;
- private Query findFilesForArchive;
-
public List listCaches(Connection con)
{
return con.createQuery("select id, revision, date from cache")
@@ -94,22 +87,6 @@ class CacheDAO
.executeAndFetchFirst(ArchiveEntry.class);
}
- public ArchiveEntry findArchiveById(Connection con, CacheEntry cache, IndexType index, int archiveId)
- {
- return con.createQuery("select archive.id, archive.archiveId, archive.nameHash,"
- + " archive.crc, archive.revision, archive.hash from archive "
- + "join index_archive on index_archive.archive = archive.id "
- + "join `index` on index.id = index_archive.index "
- + "where index.cache = :cacheId "
- + "and index.indexId = :indexId "
- + "and archive.archiveId = :archiveId "
- + "limit 1")
- .addParameter("cacheId", cache.getId())
- .addParameter("indexId", index.getNumber())
- .addParameter("archiveId", archiveId)
- .executeAndFetchFirst(ArchiveEntry.class);
- }
-
public ArchiveEntry findArchiveByName(Connection con, CacheEntry cache, IndexType index, int nameHash)
{
return con.createQuery("select archive.id, archive.archiveId, archive.nameHash,"
@@ -128,32 +105,14 @@ class CacheDAO
public ResultSetIterable findFilesForArchive(Connection con, ArchiveEntry archiveEntry)
{
- if (findFilesForArchive == null)
- {
- findFilesForArchive = con.createQuery("select id, fileId, nameHash from file "
- + "where archive = :archive");
- }
+ Query findFilesForArchive = con.createQuery("select id, fileId, nameHash from file "
+ + "where archive = :archive");
return findFilesForArchive
.addParameter("archive", archiveEntry.getId())
.executeAndFetchLazy(FileEntry.class);
}
- public CacheEntry createCache(Connection con, int revision, Instant date)
- {
- int cacheId = con.createQuery("insert into cache (revision, date) values (:revision, :date)")
- .addParameter("revision", revision)
- .addParameter("date", date)
- .executeUpdate()
- .getKey(int.class);
-
- CacheEntry entry = new CacheEntry();
- entry.setId(cacheId);
- entry.setRevision(revision);
- entry.setDate(date);
- return entry;
- }
-
public CacheEntry findCache(Connection con, int cacheId)
{
return con.createQuery("select id, revision, date from cache "
@@ -161,101 +120,4 @@ class CacheDAO
.addParameter("cacheId", cacheId)
.executeAndFetchFirst(CacheEntry.class);
}
-
- public IndexEntry createIndex(Connection con, CacheEntry cache, int indexId, int crc, int revision)
- {
- int id = con.createQuery("insert into `index` (cache, indexId, crc, revision) values (:cache, :indexId, :crc, :revision)")
- .addParameter("cache", cache.getId())
- .addParameter("indexId", indexId)
- .addParameter("crc", crc)
- .addParameter("revision", revision)
- .executeUpdate()
- .getKey(int.class);
-
- IndexEntry entry = new IndexEntry();
- entry.setId(id);
- entry.setIndexId(indexId);
- entry.setCrc(crc);
- entry.setRevision(revision);
- return entry;
- }
-
- public void associateArchiveToIndex(Connection con, ArchiveEntry archive, IndexEntry index)
- {
- if (associateArchive == null)
- {
- associateArchive = con.createQuery("insert into index_archive (`index`, archive) values (:index, :archive)");
- }
- associateArchive
- .addParameter("index", index.getId())
- .addParameter("archive", archive.getId())
- .executeUpdate();
- }
-
- public ArchiveEntry findArchive(Connection con, IndexEntry index,
- int archiveId, int nameHash, int crc, int revision)
- {
- if (findArchive == null)
- {
- findArchive = con.createQuery("select distinct archive.id, archive.archiveId, archive.nameHash,"
- + " archive.crc, archive.revision, archive.hash from archive "
- + " join index_archive on index_archive.archive = archive.id"
- + " join `index` on index.id = index_archive.index"
- + " where archive.archiveId = :archiveId"
- + " and archive.nameHash = :nameHash"
- + " and archive.crc = :crc"
- + " and archive.revision = :revision"
- + " and index.indexId = :indexId");
- }
-
- ArchiveEntry entry = findArchive
- .addParameter("archiveId", archiveId)
- .addParameter("nameHash", nameHash)
- .addParameter("crc", crc)
- .addParameter("revision", revision)
- .addParameter("indexId", index.getIndexId())
- .executeAndFetchFirst(ArchiveEntry.class);
- return entry;
- }
-
- public ArchiveEntry createArchive(Connection con, IndexEntry index,
- int archiveId, int nameHash, int crc, int revision, byte[] hash)
- {
- if (insertArchive == null)
- {
- insertArchive = con.createQuery("insert into archive (archiveId, nameHash, crc, revision, hash) values "
- + "(:archiveId, :nameHash, :crc, :revision, :hash)");
- }
-
- int id = insertArchive
- .addParameter("archiveId", archiveId)
- .addParameter("nameHash", nameHash)
- .addParameter("crc", crc)
- .addParameter("revision", revision)
- .addParameter("hash", hash)
- .executeUpdate()
- .getKey(int.class);
-
- ArchiveEntry entry = new ArchiveEntry();
- entry.setId(id);
- entry.setArchiveId(archiveId);
- entry.setNameHash(nameHash);
- entry.setCrc(crc);
- entry.setRevision(revision);
- entry.setHash(hash);
- return entry;
- }
-
- public void associateFileToArchive(Connection con, ArchiveEntry archive, int fileId, int nameHash)
- {
- if (associateFile == null)
- {
- associateFile = con.createQuery("insert into file (archive, fileId, nameHash) values (:archive, :fileId, :nameHash)");
- }
- associateFile
- .addParameter("archive", archive.getId())
- .addParameter("fileId", fileId)
- .addParameter("nameHash", nameHash)
- .executeUpdate();
- }
}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java
index 7b246eaa95..acda96e77f 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java
+++ b/http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java
@@ -24,8 +24,9 @@
*/
package net.runelite.http.service.cache.beans;
-import java.util.Arrays;
+import lombok.Data;
+@Data
public class ArchiveEntry
{
private int id;
@@ -34,127 +35,4 @@ public class ArchiveEntry
private int crc;
private int revision;
private byte[] hash;
-
- @Override
- public String toString()
- {
- return "ArchiveEntry{" + "id=" + id + ", archiveId=" + archiveId + ", nameHash=" + nameHash + ", crc=" + crc + ", revision=" + revision + '}';
- }
-
- @Override
- public int hashCode()
- {
- int hash = 3;
- hash = 53 * hash + this.id;
- hash = 53 * hash + this.archiveId;
- hash = 53 * hash + this.nameHash;
- hash = 53 * hash + this.crc;
- hash = 53 * hash + this.revision;
- hash = 53 * hash + Arrays.hashCode(this.hash);
- return hash;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- final ArchiveEntry other = (ArchiveEntry) obj;
- if (this.id != other.id)
- {
- return false;
- }
- if (this.archiveId != other.archiveId)
- {
- return false;
- }
- if (this.nameHash != other.nameHash)
- {
- return false;
- }
- if (this.crc != other.crc)
- {
- return false;
- }
- if (this.revision != other.revision)
- {
- return false;
- }
- if (!Arrays.equals(this.hash, other.hash))
- {
- return false;
- }
- return true;
- }
-
- public int getId()
- {
- return id;
- }
-
- public void setId(int id)
- {
- this.id = id;
- }
-
- public int getArchiveId()
- {
- return archiveId;
- }
-
- public void setArchiveId(int archiveId)
- {
- this.archiveId = archiveId;
- }
-
- public int getNameHash()
- {
- return nameHash;
- }
-
- public void setNameHash(int nameHash)
- {
- this.nameHash = nameHash;
- }
-
- public int getCrc()
- {
- return crc;
- }
-
- public void setCrc(int crc)
- {
- this.crc = crc;
- }
-
- public int getRevision()
- {
- return revision;
- }
-
- public void setRevision(int revision)
- {
- this.revision = revision;
- }
-
- public byte[] getHash()
- {
- return hash;
- }
-
- public void setHash(byte[] hash)
- {
- this.hash = hash;
- }
-
}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java
index 050a42688b..231ad7c655 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java
+++ b/http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java
@@ -25,88 +25,12 @@
package net.runelite.http.service.cache.beans;
import java.time.Instant;
-import java.util.Objects;
+import lombok.Data;
+@Data
public class CacheEntry
{
private int id;
private int revision;
private Instant date;
-
- @Override
- public String toString()
- {
- return "CacheEntry{" + "id=" + id + ", revision=" + revision + ", date=" + date + '}';
- }
-
- @Override
- public int hashCode()
- {
- int hash = 7;
- hash = 23 * hash + this.id;
- hash = 23 * hash + this.revision;
- hash = 23 * hash + Objects.hashCode(this.date);
- return hash;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- final CacheEntry other = (CacheEntry) obj;
- if (this.id != other.id)
- {
- return false;
- }
- if (this.revision != other.revision)
- {
- return false;
- }
- if (!Objects.equals(this.date, other.date))
- {
- return false;
- }
- return true;
- }
-
- public int getId()
- {
- return id;
- }
-
- public void setId(int id)
- {
- this.id = id;
- }
-
- public int getRevision()
- {
- return revision;
- }
-
- public void setRevision(int revision)
- {
- this.revision = revision;
- }
-
- public Instant getDate()
- {
- return date;
- }
-
- public void setDate(Instant date)
- {
- this.date = date;
- }
}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java
index ee57712e0f..c5f35a4cc3 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java
+++ b/http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java
@@ -24,103 +24,13 @@
*/
package net.runelite.http.service.cache.beans;
+import lombok.Data;
+
+@Data
public class FileEntry
{
private int id;
private int archiveId;
private int fileId;
private int nameHash;
-
- @Override
- public String toString()
- {
- return "FileEntry{" + "id=" + id + ", archiveId=" + archiveId + ", fileId=" + fileId + ", nameHash=" + nameHash + '}';
- }
-
- @Override
- public int hashCode()
- {
- int hash = 5;
- hash = 67 * hash + this.id;
- hash = 67 * hash + this.archiveId;
- hash = 67 * hash + this.fileId;
- hash = 67 * hash + this.nameHash;
- return hash;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- final FileEntry other = (FileEntry) obj;
- if (this.id != other.id)
- {
- return false;
- }
- if (this.archiveId != other.archiveId)
- {
- return false;
- }
- if (this.fileId != other.fileId)
- {
- return false;
- }
- if (this.nameHash != other.nameHash)
- {
- return false;
- }
- return true;
- }
-
- public int getId()
- {
- return id;
- }
-
- public void setId(int id)
- {
- this.id = id;
- }
-
- public int getArchiveId()
- {
- return archiveId;
- }
-
- public void setArchiveId(int archiveId)
- {
- this.archiveId = archiveId;
- }
-
- public int getFileId()
- {
- return fileId;
- }
-
- public void setFileId(int fileId)
- {
- this.fileId = fileId;
- }
-
- public int getNameHash()
- {
- return nameHash;
- }
-
- public void setNameHash(int nameHash)
- {
- this.nameHash = nameHash;
- }
-
}
diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java
index 7f89eff79c..8d60927c71 100644
--- a/http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java
+++ b/http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java
@@ -24,102 +24,13 @@
*/
package net.runelite.http.service.cache.beans;
+import lombok.Data;
+
+@Data
public class IndexEntry
{
private int id;
private int indexId;
private int crc;
private int revision;
-
- @Override
- public String toString()
- {
- return "IndexEntry{" + "id=" + id + ", indexId=" + indexId + ", crc=" + crc + ", revision=" + revision + '}';
- }
-
- @Override
- public int hashCode()
- {
- int hash = 5;
- hash = 17 * hash + this.id;
- hash = 17 * hash + this.indexId;
- hash = 17 * hash + this.crc;
- hash = 17 * hash + this.revision;
- return hash;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- final IndexEntry other = (IndexEntry) obj;
- if (this.id != other.id)
- {
- return false;
- }
- if (this.indexId != other.indexId)
- {
- return false;
- }
- if (this.crc != other.crc)
- {
- return false;
- }
- if (this.revision != other.revision)
- {
- return false;
- }
- return true;
- }
-
- public int getId()
- {
- return id;
- }
-
- public void setId(int id)
- {
- this.id = id;
- }
-
- public int getIndexId()
- {
- return indexId;
- }
-
- public void setIndexId(int indexId)
- {
- this.indexId = indexId;
- }
-
- public int getCrc()
- {
- return crc;
- }
-
- public void setCrc(int crc)
- {
- this.crc = crc;
- }
-
- public int getRevision()
- {
- return revision;
- }
-
- public void setRevision(int revision)
- {
- this.revision = revision;
- }
}
diff --git a/http-service/src/test/resources/application.properties b/http-service/src/test/resources/application.properties
index bdaf64e9db..4d93d9bb41 100644
--- a/http-service/src/test/resources/application.properties
+++ b/http-service/src/test/resources/application.properties
@@ -4,4 +4,3 @@ minio.endpoint=http://10.96.22.171:9000
minio.accesskey=AM54M27O4WZK65N6F8IP
minio.secretkey=/PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP
minio.bucket=runelite
-auth.password=password
diff --git a/pom.xml b/pom.xml
index dd633773bb..6fc09acace 100644
--- a/pom.xml
+++ b/pom.xml
@@ -114,6 +114,7 @@
cache
cache-client
cache-server
+ cache-updater
deobfuscator
model-viewer
runelite-api