use of org.apache.geode.internal.security.SecurityService in project geode by apache.
the class DeployCommands method deploy.
/**
* Deploy one or more JAR files to members of a group or all members.
*
* @param groups Group(s) to deploy the JAR to or null for all members
* @param jar JAR file to deploy
* @param dir Directory of JAR files to deploy
* @return The result of the attempt to deploy
*/
@CliCommand(value = { CliStrings.DEPLOY }, help = CliStrings.DEPLOY__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.DeployCommands$Interceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
public Result deploy(@CliOption(key = { CliStrings.DEPLOY__GROUP }, help = CliStrings.DEPLOY__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) String[] groups, @CliOption(key = { CliStrings.DEPLOY__JAR }, help = CliStrings.DEPLOY__JAR__HELP) String jar, @CliOption(key = { CliStrings.DEPLOY__DIR }, help = CliStrings.DEPLOY__DIR__HELP) String dir) {
try {
// since deploy function can potentially do a lot of damage to security, this action should
// require these following privileges
SecurityService securityService = SecurityService.getSecurityService();
securityService.authorizeClusterManage();
securityService.authorizeClusterWrite();
securityService.authorizeDataManage();
securityService.authorizeDataWrite();
TabularResultData tabularData = ResultBuilder.createTabularResultData();
byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
String[] jarNames = CliUtil.bytesToNames(shellBytesData);
byte[][] jarBytes = CliUtil.bytesToData(shellBytesData);
Set<DistributedMember> targetMembers;
targetMembers = CliUtil.findMembers(groups, null);
if (targetMembers.size() > 0) {
// this deploys the jars to all the matching servers
ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(this.deployFunction, new Object[] { jarNames, jarBytes }, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) resultCollector.getResult());
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Deployed JAR", "");
tabularData.accumulate("Deployed JAR Location", "ERROR: " + result.getThrowable().getClass().getName() + ": " + result.getThrowable().getMessage());
tabularData.setStatus(Status.ERROR);
} else {
String[] strings = (String[]) result.getSerializables();
for (int i = 0; i < strings.length; i += 2) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Deployed JAR", strings[i]);
tabularData.accumulate("Deployed JAR Location", strings[i + 1]);
}
}
}
}
Result result = ResultBuilder.buildResult(tabularData);
persistClusterConfiguration(result, () -> getSharedConfiguration().addJarsToThisLocator(jarNames, jarBytes, groups));
return result;
} catch (NotAuthorizedException e) {
// for NotAuthorizedException, will catch this later in the code
throw e;
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
return ResultBuilder.createGemFireErrorResult(String.format("Exception while attempting to deploy: (%1$s)", toString(t, isDebugging())));
}
}
Aggregations