public String toDeployName(String zipFileName) { checkState(); if (zipFileName.endsWith(".zip")) { return zipFileName.substring(0, zipFileName.length() - 4); } return zipFileName; }
/** * @return Returns <code>true</code> if the hot deploy feature is enabled, or <code>false</code> otherwise. */ @Override public boolean isHotDeployFolderActive() { checkState(); return this.properties.getBoolean("enable-hot-deploy"); }
private boolean hasPlugin(String deployName) { checkState(); File pluginFolder = new File(getWorkDirectoryUnchecked(), deployName); return pluginFolder.isDirectory(); }
/** * @return Returns <code>true</code> if the work folder cleaning feature is enabled, <code>false</code> otherwise. */ @Override public boolean isCleanWorkDirectory() { checkState(); return this.properties.getBoolean("clean-work-folder"); }
@Override public String toDeployName(File file) { checkState(); return toDeployName(file.getName()); }
/** * This is the subfolder for deployed classpath access by the limbus container. Files here are assumed to be readable * exclusively by the container. */ private String workFolder() { checkState(); return this.properties.getProperty("work-folder"); }
public File getPluginDirectoryUnchecked(String deployName) throws Exception { checkState(); File workDirectory = getOrFailWorkDirectory(); return new File(workDirectory, deployName); }
@Override public String toDeployName(String groupId, String artifactId, String extension, String version) { checkState(); extension = defaultExtensionIfNull(extension); return String.format("%s_%s_%s_%s", groupId, artifactId, extension, version); }
/** * Reads the subfolder for hot deploy from the properties. Files here are intended to be added and removed to signal a * (un)deploy via filesystem. */ private String deployFolder() { checkState(); return this.properties.getProperty("deploy-folder"); }
@Override public File getDeployDirectoryUnchecked() { checkState(); File deployFolder = new File(getCurrentDirectory(), deployFolder()); return deployFolder; }
@Override public File getWorkDirectoryUnchecked() { checkState(); File folder = new File(getCurrentDirectory(), workFolder()); return folder; }
private File getCreateOrFailPluginDirectory(String deployName) throws Exception { checkState(); File deployDirectory = getPluginDirectoryUnchecked(deployName); try { if (!deployDirectory.exists()) { deployDirectory.mkdir(); } return getOrFailDirectory("plugin", deployDirectory); } catch (Exception e) { throw new LimbusException( String.format("Cannot create plugin deploy folder %s", deployDirectory.getAbsolutePath()), e); } }
public File getOrFailPluginDirectory(String deployName) throws Exception { checkState(); return getOrFailDirectory("plugin", getPluginDirectoryUnchecked(deployName)); }
/** * @return Returns the list of known deploy names deployed by deploy service. */ @Override public List<String> getDeployedComponents() { checkState(); List<String> deployNames = new LinkedList<>(); try { File workDirectory = getOrFailWorkDirectory(); File[] listFiles = workDirectory.listFiles(); for (File file : listFiles) { if (isAccessibleDirectory(file)) { deployNames.add(file.getName()); } } } catch (Exception e) { log.error("Limbus deploy service cannot access the filesystem.", e); } return deployNames; }
public File getOrFailWorkDirectory() throws Exception { checkState(); return getOrFailDirectory("work", getWorkDirectoryUnchecked()); }
public File getOrFailDeployDir() throws Exception { checkState(); return getOrFailDirectory("deploy", getDeployDirectoryUnchecked()); }
public File getCreateOrFailDeployDirectory() throws Exception { checkState(); File deployFolder = getDeployDirectoryUnchecked(); createIfMissingDirectory(deployFolder); return getOrFailDirectory("deploy", deployFolder); }
public File getCreateOrFailWorkDirectory() throws Exception { checkState(); File folder = getWorkDirectoryUnchecked(); createIfMissingDirectory(folder); return getOrFailDirectory("work", folder); }
private void undeployFromFilesystem(String deployName) throws LimbusException { checkState(); if (hasPlugin(deployName)) { Classpath classpath = findPlugin(deployName); try { container.undeployPlugin(classpath); } finally { removePlugin(deployName); } } }
/** * Searches a plugin in the {@link #workFolder()} folder. The plugin name is used as folder name. If * present, the classpath object is created and returned. * * @param deployName * The plugin name is the folder that contains the deployment. * * @return Returns the classpath object if the plugin folder is present. * @throws LimbusException * Thrown if the plugin is not deployed. */ private Classpath findPlugin(String deployName) throws LimbusException { checkState(); try { File pluginDirectory = getOrFailPluginDirectory(deployName); return Classpath.create(deployName) .addAllFilesInDirectory(pluginDirectory); } catch (Exception e) { throw new LimbusException("Cannot find plugin due to exception.", e); } }