private void undeployFromFilesystem(String deployName) throws LimbusException { checkState(); if (hasPlugin(deployName)) { Classpath classpath = findPlugin(deployName); try { container.undeployPlugin(classpath); } finally { removePlugin(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); }
@Override public File getDeployDirectoryUnchecked() { checkState(); File deployFolder = new File(getCurrentDirectory(), deployFolder()); return deployFolder; }
@Override public String toDeployName(File file) { checkState(); return toDeployName(file.getName()); }
public File getPluginDirectoryUnchecked(String deployName) throws Exception { checkState(); File workDirectory = getOrFailWorkDirectory(); return new File(workDirectory, deployName); }
public void deployMavenArtifact(String groupId, String artifactId, String extension, String version, Set<Permission> permissions) throws LimbusException { checkState(); extension = defaultExtensionIfNull(extension); String deployName = toDeployName(groupId, artifactId, extension, version); try { File pluginDirectory = getCreateOrFailPluginDirectory(deployName); deployFromFilesystem(deployName, permissions); removePlugin(deployName);
@Override protected void performInitialize() throws LimbusException { try { // Create the properties this.properties = new LimbusProperties(filesystem, getClass(), true, false); // Register as a deployment listener container.addDeploymentListener(this); // When created by the container, clean old deployments cleanWorkDirectory(); // Make sure work folder is available getCreateOrFailWorkDirectory(); // Make sure deploy folder is available getCreateOrFailDeployDirectory(); // Start hot deploy listener startFileDeployWatchService(); // Deploy all artifacts from deploy directory. deployAll(); } catch (Exception e) { throw new LimbusException("Cannot initialize Limbus Deploy Service.", e); } }
/** * Deploys the specified ZIP file to this container. * * @param zipDeployment * The ZIP file. * @param permissions * The permissions to be granted for classes of this classpath. * @throws LimbusException * Thrown on any error while unpacking or deploying this ZIP file. */ @Override public void deployZipFile(File zipDeployment, Set<Permission> permissions) throws LimbusException { checkState(); String deployName = toDeployName(zipDeployment.getName()); if (hasPlugin(deployName)) { throw new LimbusException(String.format("The plugin '%s' is already deployed.", deployName)); } try { File deployDirectory = getCreateOrFailPluginDirectory(deployName); Zip.unpack(zipDeployment, deployDirectory); } catch (Exception e) { throw new LimbusException(String.format("Cannot unpack ZIP plugin bundle %s", zipDeployment.getAbsolutePath()), e); } // Trigger deploy deployFromFilesystem(deployName, permissions); }
/** * Starts the deploy process for an artifact already present in the containers work directory. * * @param deployName * The deploy name * @param permissions * The permissions to be granted for classes of this classpath. * @throws LimbusException * Thrown on any error while deploying. */ @Override public void deployFromFilesystem(String deployName, Set<Permission> permissions) throws LimbusException { checkState(); try { File pluginDirectory = getCreateOrFailPluginDirectory(deployName); // Create the classpath of the deployed files Classpath classpath = Classpath.create(deployName) .addAllFilesInDirectory(pluginDirectory); container.deployPlugin(classpath, permissions); } catch (Exception e) { // Clean deployed files from work removePlugin(deployName); // Forward deploy exception throw new LimbusException(String.format("Cannot deploy the specified classpath with deploy name %s", deployName), e); } }
private boolean hasPlugin(String deployName) { checkState(); File pluginFolder = new File(getWorkDirectoryUnchecked(), deployName); return pluginFolder.isDirectory(); }
public File getOrFailDeployDir() throws Exception { checkState(); return getOrFailDirectory("deploy", getDeployDirectoryUnchecked()); }
public File getOrFailPluginDirectory(String deployName) throws Exception { checkState(); return getOrFailDirectory("plugin", getPluginDirectoryUnchecked(deployName)); }
@Override public File getWorkDirectoryUnchecked() { checkState(); File folder = new File(getCurrentDirectory(), workFolder()); return folder; }
/** * 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); } }
private void startFileDeployWatchService() throws LimbusException { if (isHotDeployFolderActive()) { try { this.dir = Paths.get(".", deployFolder()) .toAbsolutePath() .normalize();
String deployName = toDeployName(zipDeployment.getName()); deployZipFile(zipDeployment, limbusSecurity.getSandboxDefaultPermissions()); } catch (LimbusException e) { log.error(String.format("Error while deploying a ZIP bundle from filesystem: %s (%s)", deployName,
try { File deployDir = getCreateOrFailDeployDirectory(); File[] toDeploys = deployDir.listFiles(new FileFilter() { deployZipFile(toDeploy, limbusSecurity.getSandboxDefaultPermissions()); } catch (LimbusException e) { exceptions.add(e);
List<String> deployedComponents = getDeployedComponents(); for (String deployName : deployedComponents) { try { container.undeployPlugin(findPlugin(deployName)); } catch (LimbusException e) { log.error(String.format("Cannot undeploy the deployment with name \'%s\'.", deployName), e);
public String toDeployName(String zipFileName) { checkState(); if (zipFileName.endsWith(".zip")) { return zipFileName.substring(0, zipFileName.length() - 4); } return zipFileName; }
public File getOrFailWorkDirectory() throws Exception { checkState(); return getOrFailDirectory("work", getWorkDirectoryUnchecked()); }