Split out cache updater into own project
This commit is contained in:
7
cache-updater/application.properties
Normal file
7
cache-updater/application.properties
Normal file
@@ -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
|
||||||
105
cache-updater/pom.xml
Normal file
105
cache-updater/pom.xml
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>net.runelite</groupId>
|
||||||
|
<artifactId>runelite-parent</artifactId>
|
||||||
|
<version>1.2.15-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<name>Cache Updater</name>
|
||||||
|
<artifactId>cache-updater</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring.boot.version>1.5.6.RELEASE</spring.boot.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>${spring.boot.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
<version>${spring.boot.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<version>${spring.boot.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.45</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.runelite</groupId>
|
||||||
|
<artifactId>cache-client</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sql2o</groupId>
|
||||||
|
<artifactId>sql2o</artifactId>
|
||||||
|
<version>1.5.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.minio</groupId>
|
||||||
|
<artifactId>minio</artifactId>
|
||||||
|
<version>3.0.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring.boot.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<classifier>spring-boot</classifier>
|
||||||
|
<mainClass>net.runelite.cache.updater.CacheUpdater</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
88
cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java
vendored
Normal file
88
cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java
vendored
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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<Class, Converter> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
177
cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java
vendored
Normal file
177
cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java
vendored
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* 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<IndexEntry> 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<ArchiveEntry> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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.io.IOException;
|
||||||
import java.util.List;
|
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.Storage;
|
||||||
import net.runelite.cache.fs.Store;
|
import net.runelite.cache.fs.Store;
|
||||||
import net.runelite.cache.index.FileData;
|
import net.runelite.cache.index.FileData;
|
||||||
import net.runelite.http.service.cache.beans.ArchiveEntry;
|
import net.runelite.cache.updater.beans.ArchiveEntry;
|
||||||
import net.runelite.http.service.cache.beans.CacheEntry;
|
import net.runelite.cache.updater.beans.CacheEntry;
|
||||||
import net.runelite.http.service.cache.beans.IndexEntry;
|
import net.runelite.cache.updater.beans.IndexEntry;
|
||||||
import org.sql2o.Connection;
|
import org.sql2o.Connection;
|
||||||
import org.sql2o.ResultSetIterable;
|
import org.sql2o.ResultSetIterable;
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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.MinioClient;
|
||||||
import io.minio.errors.InvalidEndpointException;
|
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.client.IndexInfo;
|
||||||
import net.runelite.cache.fs.Archive;
|
import net.runelite.cache.fs.Archive;
|
||||||
import net.runelite.cache.fs.Store;
|
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.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 net.runelite.protocol.api.login.HandshakeResponseType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.sql2o.Connection;
|
import org.sql2o.Connection;
|
||||||
import org.sql2o.Sql2o;
|
import org.sql2o.Sql2o;
|
||||||
|
|
||||||
@RestController
|
@SpringBootApplication
|
||||||
@RequestMapping("/cache/admin")
|
public class CacheUpdater implements CommandLineRunner
|
||||||
public class CacheUpdater
|
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CacheUpdater.class);
|
private static final Logger logger = LoggerFactory.getLogger(CacheUpdater.class);
|
||||||
|
|
||||||
private final Sql2o sql2o;
|
private final Sql2o sql2o;
|
||||||
private final MinioClient minioClient;
|
private final MinioClient minioClient;
|
||||||
|
|
||||||
@Value("${minio.bucket}")
|
@Value("${minio.bucket}")
|
||||||
private String minioBucket;
|
private String minioBucket;
|
||||||
|
|
||||||
@@ -73,8 +73,7 @@ public class CacheUpdater
|
|||||||
this.minioClient = minioClient;
|
this.minioClient = minioClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/update")
|
public void update() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException
|
||||||
public void check() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException
|
|
||||||
{
|
{
|
||||||
int rsVersion = RuneLiteAPI.getRsVersion();
|
int rsVersion = RuneLiteAPI.getRsVersion();
|
||||||
|
|
||||||
@@ -103,7 +102,8 @@ public class CacheUpdater
|
|||||||
|
|
||||||
if (result != HandshakeResponseType.RESPONSE_OK)
|
if (result != HandshakeResponseType.RESPONSE_OK)
|
||||||
{
|
{
|
||||||
throw new OutOfDateException();
|
logger.warn("Out of date!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<IndexInfo> indexes = client.requestIndexes();
|
List<IndexInfo> indexes = client.requestIndexes();
|
||||||
@@ -158,4 +158,16 @@ public class CacheUpdater
|
|||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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.hash.Hashing;
|
||||||
import com.google.common.io.BaseEncoding;
|
import com.google.common.io.BaseEncoding;
|
||||||
48
cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java
vendored
Normal file
48
cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* 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<Instant>
|
||||||
|
{
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,45 +22,17 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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 lombok.Data;
|
||||||
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;
|
|
||||||
|
|
||||||
@Configuration
|
@Data
|
||||||
@EnableWebSecurity
|
public class ArchiveEntry
|
||||||
@Order(200)
|
|
||||||
public class CacheSecurity extends WebSecurityConfigurerAdapter
|
|
||||||
{
|
{
|
||||||
@Value("${auth.password}")
|
private int id;
|
||||||
private String password;
|
private int archiveId;
|
||||||
|
private int nameHash;
|
||||||
@Override
|
private int crc;
|
||||||
protected void configure(HttpSecurity http) throws Exception
|
private int revision;
|
||||||
{
|
private byte[] hash;
|
||||||
// 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,12 +22,15 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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")
|
@Data
|
||||||
public class OutOfDateException extends RuntimeException
|
public class CacheEntry
|
||||||
{
|
{
|
||||||
|
private int id;
|
||||||
|
private int revision;
|
||||||
|
private Instant date;
|
||||||
}
|
}
|
||||||
36
cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java
vendored
Normal file
36
cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
36
cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java
vendored
Normal file
36
cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
@@ -52,11 +52,6 @@
|
|||||||
<version>${spring.boot.version}</version>
|
<version>${spring.boot.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
|
||||||
<version>${spring.boot.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
@@ -85,11 +80,6 @@
|
|||||||
<artifactId>cache</artifactId>
|
<artifactId>cache</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.runelite</groupId>
|
|
||||||
<artifactId>cache-client</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.sql2o</groupId>
|
<groupId>org.sql2o</groupId>
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.cache;
|
package net.runelite.http.service.cache;
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.cache.IndexType;
|
import net.runelite.cache.IndexType;
|
||||||
import net.runelite.http.service.cache.beans.ArchiveEntry;
|
import net.runelite.http.service.cache.beans.ArchiveEntry;
|
||||||
@@ -37,12 +36,6 @@ import org.sql2o.ResultSetIterable;
|
|||||||
|
|
||||||
class CacheDAO
|
class CacheDAO
|
||||||
{
|
{
|
||||||
// cache prepared statements for high volume queries
|
|
||||||
private Query associateArchive;
|
|
||||||
private Query findArchive, insertArchive;
|
|
||||||
private Query associateFile;
|
|
||||||
private Query findFilesForArchive;
|
|
||||||
|
|
||||||
public List<CacheEntry> listCaches(Connection con)
|
public List<CacheEntry> listCaches(Connection con)
|
||||||
{
|
{
|
||||||
return con.createQuery("select id, revision, date from cache")
|
return con.createQuery("select id, revision, date from cache")
|
||||||
@@ -94,22 +87,6 @@ class CacheDAO
|
|||||||
.executeAndFetchFirst(ArchiveEntry.class);
|
.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)
|
public ArchiveEntry findArchiveByName(Connection con, CacheEntry cache, IndexType index, int nameHash)
|
||||||
{
|
{
|
||||||
return con.createQuery("select archive.id, archive.archiveId, archive.nameHash,"
|
return con.createQuery("select archive.id, archive.archiveId, archive.nameHash,"
|
||||||
@@ -128,32 +105,14 @@ class CacheDAO
|
|||||||
|
|
||||||
public ResultSetIterable<FileEntry> findFilesForArchive(Connection con, ArchiveEntry archiveEntry)
|
public ResultSetIterable<FileEntry> findFilesForArchive(Connection con, ArchiveEntry archiveEntry)
|
||||||
{
|
{
|
||||||
if (findFilesForArchive == null)
|
Query findFilesForArchive = con.createQuery("select id, fileId, nameHash from file "
|
||||||
{
|
+ "where archive = :archive");
|
||||||
findFilesForArchive = con.createQuery("select id, fileId, nameHash from file "
|
|
||||||
+ "where archive = :archive");
|
|
||||||
}
|
|
||||||
|
|
||||||
return findFilesForArchive
|
return findFilesForArchive
|
||||||
.addParameter("archive", archiveEntry.getId())
|
.addParameter("archive", archiveEntry.getId())
|
||||||
.executeAndFetchLazy(FileEntry.class);
|
.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)
|
public CacheEntry findCache(Connection con, int cacheId)
|
||||||
{
|
{
|
||||||
return con.createQuery("select id, revision, date from cache "
|
return con.createQuery("select id, revision, date from cache "
|
||||||
@@ -161,101 +120,4 @@ class CacheDAO
|
|||||||
.addParameter("cacheId", cacheId)
|
.addParameter("cacheId", cacheId)
|
||||||
.executeAndFetchFirst(CacheEntry.class);
|
.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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.cache.beans;
|
package net.runelite.http.service.cache.beans;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class ArchiveEntry
|
public class ArchiveEntry
|
||||||
{
|
{
|
||||||
private int id;
|
private int id;
|
||||||
@@ -34,127 +35,4 @@ public class ArchiveEntry
|
|||||||
private int crc;
|
private int crc;
|
||||||
private int revision;
|
private int revision;
|
||||||
private byte[] hash;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,88 +25,12 @@
|
|||||||
package net.runelite.http.service.cache.beans;
|
package net.runelite.http.service.cache.beans;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Objects;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class CacheEntry
|
public class CacheEntry
|
||||||
{
|
{
|
||||||
private int id;
|
private int id;
|
||||||
private int revision;
|
private int revision;
|
||||||
private Instant date;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,103 +24,13 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.cache.beans;
|
package net.runelite.http.service.cache.beans;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class FileEntry
|
public class FileEntry
|
||||||
{
|
{
|
||||||
private int id;
|
private int id;
|
||||||
private int archiveId;
|
private int archiveId;
|
||||||
private int fileId;
|
private int fileId;
|
||||||
private int nameHash;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,102 +24,13 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.cache.beans;
|
package net.runelite.http.service.cache.beans;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class IndexEntry
|
public class IndexEntry
|
||||||
{
|
{
|
||||||
private int id;
|
private int id;
|
||||||
private int indexId;
|
private int indexId;
|
||||||
private int crc;
|
private int crc;
|
||||||
private int revision;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,3 @@ minio.endpoint=http://10.96.22.171:9000
|
|||||||
minio.accesskey=AM54M27O4WZK65N6F8IP
|
minio.accesskey=AM54M27O4WZK65N6F8IP
|
||||||
minio.secretkey=/PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP
|
minio.secretkey=/PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP
|
||||||
minio.bucket=runelite
|
minio.bucket=runelite
|
||||||
auth.password=password
|
|
||||||
|
|||||||
1
pom.xml
1
pom.xml
@@ -114,6 +114,7 @@
|
|||||||
<module>cache</module>
|
<module>cache</module>
|
||||||
<module>cache-client</module>
|
<module>cache-client</module>
|
||||||
<module>cache-server</module>
|
<module>cache-server</module>
|
||||||
|
<module>cache-updater</module>
|
||||||
<module>deobfuscator</module>
|
<module>deobfuscator</module>
|
||||||
<module>model-viewer</module>
|
<module>model-viewer</module>
|
||||||
<module>runelite-api</module>
|
<module>runelite-api</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user