use of org.apache.geode.internal.DeployedJar in project geode by apache.
the class DeployFunction method execute.
@Override
public void execute(FunctionContext context) {
// Declared here so that it's available when returning a Throwable
String memberId = "";
try {
final Object[] args = (Object[]) context.getArguments();
final String[] jarFilenames = (String[]) args[0];
final byte[][] jarBytes = (byte[][]) args[1];
InternalCache cache = getCache();
final JarDeployer jarDeployer = new JarDeployer(cache.getInternalDistributedSystem().getConfig().getDeployWorkingDir());
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
memberId = member.getId();
// If they set a name use it instead
if (!member.getName().equals("")) {
memberId = member.getName();
}
List<String> deployedList = new ArrayList<String>();
List<DeployedJar> jarClassLoaders = ClassPathLoader.getLatest().getJarDeployer().deploy(jarFilenames, jarBytes);
for (int i = 0; i < jarFilenames.length; i++) {
deployedList.add(jarFilenames[i]);
if (jarClassLoaders.get(i) != null) {
deployedList.add(jarClassLoaders.get(i).getFileCanonicalPath());
} else {
deployedList.add("Already deployed");
}
}
CliFunctionResult result = new CliFunctionResult(memberId, deployedList.toArray(new String[0]));
context.getResultSender().lastResult(result);
} catch (CacheClosedException cce) {
CliFunctionResult result = new CliFunctionResult(memberId, false, null);
context.getResultSender().lastResult(result);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
logger.error("Could not deploy JAR file {}", th.getMessage(), th);
CliFunctionResult result = new CliFunctionResult(memberId, th, null);
context.getResultSender().lastResult(result);
}
}
use of org.apache.geode.internal.DeployedJar in project geode by apache.
the class ListDeployedFunction method execute.
@Override
public void execute(FunctionContext context) {
// Declared here so that it's available when returning a Throwable
String memberId = "";
try {
InternalCache cache = getCache();
final JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer();
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
memberId = member.getId();
// If they set a name use it instead
if (!member.getName().equals("")) {
memberId = member.getName();
}
final List<DeployedJar> jarClassLoaders = jarDeployer.findDeployedJars();
final String[] jars = new String[jarClassLoaders.size() * 2];
int index = 0;
for (DeployedJar jarClassLoader : jarClassLoaders) {
jars[index++] = jarClassLoader.getJarName();
jars[index++] = jarClassLoader.getFileCanonicalPath();
}
CliFunctionResult result = new CliFunctionResult(memberId, jars);
context.getResultSender().lastResult(result);
} catch (CacheClosedException cce) {
CliFunctionResult result = new CliFunctionResult(memberId, false, null);
context.getResultSender().lastResult(result);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
logger.error("Could not list JAR files: {}", th.getMessage(), th);
CliFunctionResult result = new CliFunctionResult(memberId, th, null);
context.getResultSender().lastResult(result);
}
}
use of org.apache.geode.internal.DeployedJar in project geode by apache.
the class BackupManager method backupDeployedJars.
/**
* Copies user deployed jars to the backup directory.
*
* @param restoreScript Used to restore from this backup.
* @param backupDir The backup directory for this member.
* @throws IOException one or more of the jars did not successfully copy.
*/
private void backupDeployedJars(RestoreScript restoreScript, File backupDir) throws IOException {
JarDeployer deployer = null;
try {
/*
* Suspend any user deployed jar file updates during this backup.
*/
deployer = ClassPathLoader.getLatest().getJarDeployer();
deployer.suspendAll();
List<DeployedJar> jarList = deployer.findDeployedJars();
if (!jarList.isEmpty()) {
File userBackupDir = new File(backupDir, USER_FILES);
if (!userBackupDir.exists()) {
userBackupDir.mkdir();
}
for (DeployedJar loader : jarList) {
File source = new File(loader.getFileCanonicalPath());
File dest = new File(userBackupDir, source.getName());
if (source.isDirectory()) {
FileUtils.copyDirectory(source, dest);
} else {
FileUtils.copyFile(source, dest);
}
restoreScript.addFile(source, dest);
}
}
} finally {
/*
* Re-enable user deployed jar file updates.
*/
if (null != deployer) {
deployer.resumeAll();
}
}
}
use of org.apache.geode.internal.DeployedJar in project geode by apache.
the class UndeployFunction method execute.
@Override
public void execute(FunctionContext context) {
// Declared here so that it's available when returning a Throwable
String memberId = "";
try {
final Object[] args = (Object[]) context.getArguments();
// Comma separated
final String jarFilenameList = (String) args[0];
InternalCache cache = getCache();
final JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer();
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
memberId = member.getId();
// If they set a name use it instead
if (!member.getName().equals("")) {
memberId = member.getName();
}
String[] undeployedJars = new String[0];
if (jarFilenameList == null || jarFilenameList.equals("")) {
final List<DeployedJar> jarClassLoaders = jarDeployer.findDeployedJars();
undeployedJars = new String[jarClassLoaders.size() * 2];
int index = 0;
for (DeployedJar jarClassLoader : jarClassLoaders) {
undeployedJars[index++] = jarClassLoader.getJarName();
try {
undeployedJars[index++] = ClassPathLoader.getLatest().getJarDeployer().undeploy(jarClassLoader.getJarName());
} catch (IllegalArgumentException iaex) {
// It's okay for it to have have been uneployed from this server
undeployedJars[index++] = iaex.getMessage();
}
}
} else {
List<String> undeployedList = new ArrayList<String>();
StringTokenizer jarTokenizer = new StringTokenizer(jarFilenameList, ",");
while (jarTokenizer.hasMoreTokens()) {
String jarFilename = jarTokenizer.nextToken().trim();
try {
undeployedList.add(jarFilename);
undeployedList.add(ClassPathLoader.getLatest().getJarDeployer().undeploy(jarFilename));
} catch (IllegalArgumentException iaex) {
// It's okay for it to not have been deployed to this server
undeployedList.add(iaex.getMessage());
}
}
undeployedJars = undeployedList.toArray(undeployedJars);
}
CliFunctionResult result = new CliFunctionResult(memberId, undeployedJars);
context.getResultSender().lastResult(result);
} catch (CacheClosedException cce) {
CliFunctionResult result = new CliFunctionResult(memberId, false, null);
context.getResultSender().lastResult(result);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
logger.error("Could not undeploy JAR file: {}", th.getMessage(), th);
CliFunctionResult result = new CliFunctionResult(memberId, th, null);
context.getResultSender().lastResult(result);
}
}
use of org.apache.geode.internal.DeployedJar in project geode by apache.
the class ClusterConfigurationLoader method deployJarsReceivedFromClusterConfiguration.
/**
* Deploys the jars received from shared configuration, it undeploys any other jars that were not
* part of shared configuration
*
* @param cache Cache of this member
* @param response {@link ConfigurationResponse} received from the locators
*/
public static void deployJarsReceivedFromClusterConfiguration(Cache cache, ConfigurationResponse response) throws IOException, ClassNotFoundException {
logger.info("Requesting cluster configuration");
if (response == null) {
return;
}
String[] jarFileNames = response.getJarNames();
byte[][] jarBytes = response.getJars();
logger.info("Got response with jars: {}", Stream.of(jarFileNames).collect(joining(",")));
if (jarFileNames != null && jarBytes != null) {
JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer();
jarDeployer.suspendAll();
try {
List<String> extraJarsOnServer = jarDeployer.findDeployedJars().stream().map(DeployedJar::getJarName).filter(jarName -> !ArrayUtils.contains(jarFileNames, jarName)).collect(toList());
for (String extraJar : extraJarsOnServer) {
logger.info("Removing jar not present in cluster configuration: {}", extraJar);
jarDeployer.deleteAllVersionsOfJar(extraJar);
}
List<DeployedJar> deployedJars = jarDeployer.deploy(jarFileNames, jarBytes);
deployedJars.stream().filter(Objects::nonNull).forEach((jar) -> logger.info("Deployed: {}", jar.getFile().getAbsolutePath()));
} finally {
jarDeployer.resumeAll();
}
}
}
Aggregations