Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple installation and deployment #479

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public void contextInitialized(ServletContextEvent sce) {
this.vitroHomeDir = VitroHomeDirectory.find(ctx);
ss.info(this, vitroHomeDir.getDiscoveryMessage());

this.vitroHomeDir.populate();

locateApplicationConfigFile();
loadApplicationConfigFile();
createConfigurationBeanLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@

import static edu.cornell.mannlib.vitro.webapp.application.BuildProperties.WEBAPP_PATH_BUILD_PROPERTIES;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.naming.InitialContext;
import javax.servlet.ServletContext;

import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand All @@ -32,6 +38,8 @@ public static VitroHomeDirectory find(ServletContext ctx) {
private final ServletContext ctx;
private final Path path;
private final String discoveryMessage;
private Set<String> excludedHomeFiles = new HashSet<>(Arrays.asList("rdf"));


public VitroHomeDirectory(ServletContext ctx, Path path,
String discoveryMessage) {
Expand Down Expand Up @@ -168,8 +176,7 @@ private void confirmExactlyOneResult() {
private void confirmValidDirectory() {
Path vhd = getPath();
if (!Files.exists(vhd)) {
throw new IllegalStateException("Vitro home directory '" + vhd
+ "' does not exist.");
createHomeDirectory(vhd);
}
if (!Files.isDirectory(vhd)) {
throw new IllegalStateException("Vitro home directory '" + vhd
Expand Down Expand Up @@ -210,4 +217,79 @@ public String toString() {
}
}

/**
* Populates home directory with home files, excluding the rdf directory
*/
public void populate() {
File vhdDir = getPath().toFile();

if (!vhdDir.isDirectory() || vhdDir.list() == null) {
throw new RuntimeException("Application home dir is not a directory! " + vhdDir);
}

if (!vhdDir.canWrite()) {
throw new RuntimeException("Application home dir is not writable! " + vhdDir);
}
try {
copy(vhdDir);
} catch(Exception e) {
log.error(e, e);
throw new RuntimeException("Failed to copy home files! " + vhdDir);
}
log.info("Copied home files to " + vhdDir.toPath());

}

/**
* Create home directory
*/
private static void createHomeDirectory(Path vhdDir) {
try {
vhdDir.toFile().mkdirs();
} catch (Exception e) {
log.error(e, e);
throw new RuntimeException("Failed to create home directory " + vhdDir);
}
}

/**
* Copy file from home source to home destination
*/
private void copy(File homeDestination) throws IOException {
File homeSrcPath = new File(getHomeSrcPath(ctx));
File[] contents = homeSrcPath.listFiles();
for (File child : contents) {
if (!isExcluded(child)) {
FileUtils.copyDirectory(child, homeDestination);
}
}
}

/**
* Test if file name is excluded from copying
*
* @return true if file should be excluded
*/
private boolean isExcluded(File child) {
if (excludedHomeFiles.contains(child.getName())) {
return true;
}
return false;
}

/**
* Get source home file directory path
*
* @return source home files directory path
*/
public static String getHomeSrcPath(ServletContext context) {
String location = "/WEB-INF/resources/home-files";
String realPath = context.getRealPath(location);
if (realPath == null) {
log.error("Application home files not found in: " + location);
throw new RuntimeException("Application home files not found in: " + location);
}
return realPath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;

import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.application.VitroHomeDirectory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
Expand Down Expand Up @@ -121,8 +121,8 @@ public void contextInitialized(ServletContextEvent sce) {
private Set<Path> getFilegraphPaths(ServletContext ctx, String... strings) {
StartupStatus ss = StartupStatus.getBean(ctx);

String homeDirProperty = ApplicationUtils.instance().getHomeDirectory().getPath().toString();
Path filegraphDir = Paths.get(homeDirProperty, strings);
String homeDirPath = VitroHomeDirectory.getHomeSrcPath(ctx);
Path filegraphDir = Paths.get(homeDirPath, strings);

Set<Path> paths = new TreeSet<>();
if (Files.isDirectory(filegraphDir)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.StmtIterator;

import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.application.VitroHomeDirectory;

import javax.servlet.ServletContext;

Expand Down Expand Up @@ -81,7 +81,7 @@ public boolean accept(Path p) throws IOException {
public static void loadFirstTimeFiles(ServletContext ctx, String modelPath, Model model,
boolean firstTime) {
if (firstTime) {
String home = locateHomeDirectory();
String home = locateHomeDirectory(ctx);

// Load common files
Set<Path> paths = getPaths(home, RDF, modelPath, FIRST_TIME);
Expand Down Expand Up @@ -113,7 +113,7 @@ public static void loadFirstTimeFiles(ServletContext ctx, String modelPath, Mode
public static void loadEveryTimeFiles(ServletContext ctx, String modelPath, OntModel model) {
OntModel everytimeModel = ModelFactory
.createOntologyModel(OntModelSpec.OWL_MEM);
String home = locateHomeDirectory();
String home = locateHomeDirectory(ctx);

// Load common files
Set<Path> paths = getPaths(home, RDF, modelPath, EVERY_TIME);
Expand Down Expand Up @@ -220,9 +220,8 @@ else if (filename.endsWith("ttl"))
return DEFAULT_RDF_FORMAT;
}

private static String locateHomeDirectory() {
return ApplicationUtils.instance().getHomeDirectory().getPath()
.toString();
private static String locateHomeDirectory(ServletContext ctx) {
return VitroHomeDirectory.getHomeSrcPath(ctx);
}

/**
Expand Down
87 changes: 13 additions & 74 deletions installer/home/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,101 +2,40 @@
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>

<groupId>org.vivoweb</groupId>
<artifactId>vitro-installer-home</artifactId>
<version>1.15.1-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
<groupId>org.vivoweb</groupId>
<artifactId>vitro-installer</artifactId>
<version>1.15.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<name>Vitro Install Home</name>

<properties>
<default-theme>vitro</default-theme>
</properties>

<profiles>
<profile>
<id>install</id>
<activation>
<property><name>vitro-dir</name></property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/home.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>remove-webapp</id>
<phase>verify</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete dir="${vitro-dir}/rdf" />
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${vitro-dir}</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/${project.build.finalName}</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<skip>true</skip>
<descriptors>
<descriptor>src/main/assembly/home.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
2 changes: 1 addition & 1 deletion installer/home/src/main/assembly/home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>home</id>
<formats>
<format>dir</format>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
Expand Down
Loading
Loading