use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class AddPdxEnum method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
serverConnection.setAsTrue(REQUIRES_RESPONSE);
if (logger.isDebugEnabled()) {
logger.debug("{}: Received get pdx id for enum request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
}
int noOfParts = clientMessage.getNumberOfParts();
EnumInfo enumInfo = (EnumInfo) clientMessage.getPart(0).getObject();
int enumId = clientMessage.getPart(1).getInt();
try {
InternalCache cache = serverConnection.getCache();
TypeRegistry registry = cache.getPdxRegistry();
registry.addRemoteEnum(enumId, enumInfo);
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
writeReply(clientMessage, serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class RestAgent method createParameterizedQueryRegion.
/**
* This method will create a REPLICATED region named _ParameterizedQueries__. In developer REST
* APIs, this region will be used to store the queryId and queryString as a key and value
* respectively.
*/
public static void createParameterizedQueryRegion() {
try {
if (logger.isDebugEnabled()) {
logger.debug("Starting creation of __ParameterizedQueries__ region");
}
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
if (cache != null) {
final InternalRegionArguments regionArguments = new InternalRegionArguments();
regionArguments.setIsUsedForMetaRegion(true);
final AttributesFactory<String, String> attributesFactory = new AttributesFactory<String, String>();
attributesFactory.setConcurrencyChecksEnabled(false);
attributesFactory.setDataPolicy(DataPolicy.REPLICATE);
attributesFactory.setKeyConstraint(String.class);
attributesFactory.setScope(Scope.DISTRIBUTED_ACK);
attributesFactory.setStatisticsEnabled(false);
attributesFactory.setValueConstraint(String.class);
final RegionAttributes<String, String> regionAttributes = attributesFactory.create();
cache.createVMRegion("__ParameterizedQueries__", regionAttributes, regionArguments);
if (logger.isDebugEnabled()) {
logger.debug("Successfully created __ParameterizedQueries__ region");
}
} else {
logger.error("Cannot create ParameterizedQueries Region as no cache found!");
}
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Error creating __ParameterizedQueries__ Region with cause {}", e.getMessage(), e);
}
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class ManagementAgent method startHttpService.
private void startHttpService(boolean isServer) {
final SystemManagementService managementService = (SystemManagementService) ManagementService.getManagementService(CacheFactory.getAnyInstance());
final ManagerMXBean managerBean = managementService.getManagerMXBean();
if (this.config.getHttpServicePort() != 0) {
if (logger.isDebugEnabled()) {
logger.debug("Attempting to start HTTP service on port ({}) at bind-address ({})...", this.config.getHttpServicePort(), this.config.getHttpServiceBindAddress());
}
// Find the Management WAR file
final String gemfireWar = agentUtil.findWarLocation("geode-web");
if (gemfireWar == null) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to find GemFire Management REST API WAR file; the Management REST Interface for GemFire will not be accessible.");
}
}
// Find the Pulse WAR file
final String pulseWar = agentUtil.findWarLocation("geode-pulse");
if (pulseWar == null) {
final String message = "Unable to find Pulse web application WAR file; Pulse for GemFire will not be accessible";
setStatusMessage(managerBean, message);
if (logger.isDebugEnabled()) {
logger.debug(message);
}
} else if (securityService.isIntegratedSecurity()) {
System.setProperty("spring.profiles.active", "pulse.authentication.gemfire");
}
// Find developer REST WAR file
final String gemfireAPIWar = agentUtil.findWarLocation("geode-web-api");
if (gemfireAPIWar == null) {
final String message = "Unable to find GemFire Developer REST API WAR file; the Developer REST Interface for GemFire will not be accessible.";
setStatusMessage(managerBean, message);
if (logger.isDebugEnabled()) {
logger.debug(message);
}
}
try {
if (agentUtil.isWebApplicationAvailable(gemfireWar, pulseWar, gemfireAPIWar)) {
final String bindAddress = this.config.getHttpServiceBindAddress();
final int port = this.config.getHttpServicePort();
boolean isRestWebAppAdded = false;
this.httpServer = JettyHelper.initJetty(bindAddress, port, SSLConfigurationFactory.getSSLConfigForComponent(SecurableCommunicationChannel.WEB));
if (agentUtil.isWebApplicationAvailable(gemfireWar)) {
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/gemfire", gemfireWar);
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/geode-mgmt", gemfireWar);
}
if (agentUtil.isWebApplicationAvailable(pulseWar)) {
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/pulse", pulseWar);
}
if (isServer && this.config.getStartDevRestApi()) {
if (agentUtil.isWebApplicationAvailable(gemfireAPIWar)) {
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/geode", gemfireAPIWar);
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/gemfire-api", gemfireAPIWar);
isRestWebAppAdded = true;
}
} else {
final String message = "Developer REST API web application will not start when start-dev-rest-api is not set and node is not server";
setStatusMessage(managerBean, message);
if (logger.isDebugEnabled()) {
logger.debug(message);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Starting HTTP embedded server on port ({}) at bind-address ({})...", ((ServerConnector) this.httpServer.getConnectors()[0]).getPort(), bindAddress);
}
System.setProperty(PULSE_EMBEDDED_PROP, "true");
System.setProperty(PULSE_PORT_PROP, "" + config.getJmxManagerPort());
final SocketCreator jmxSocketCreator = SocketCreatorFactory.getSocketCreatorForComponent(SecurableCommunicationChannel.JMX);
final SocketCreator locatorSocketCreator = SocketCreatorFactory.getSocketCreatorForComponent(SecurableCommunicationChannel.LOCATOR);
System.setProperty(PULSE_USESSL_MANAGER, jmxSocketCreator.useSSL() + "");
System.setProperty(PULSE_USESSL_LOCATOR, locatorSocketCreator.useSSL() + "");
this.httpServer = JettyHelper.startJetty(this.httpServer);
// clients to connect to Pulse
if (agentUtil.isWebApplicationAvailable(pulseWar)) {
managerBean.setPulseURL("http://".concat(getHost(bindAddress)).concat(":").concat(String.valueOf(port)).concat("/pulse/"));
}
// set cache property for developer REST service running
if (isRestWebAppAdded) {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
cache.setRESTServiceRunning(true);
// create region to hold query information (queryId, queryString).
// Added for the developer REST APIs
RestAgent.createParameterizedQueryRegion();
}
// set true for HTTP service running
setHttpServiceRunning(true);
}
} catch (Exception e) {
// Jetty needs to be stopped even if it has failed to
stopHttpService();
// start. Some of the threads are left behind even if
// server.start() fails due to an exception
setStatusMessage(managerBean, "HTTP service failed to start with " + e.getClass().getSimpleName() + " '" + e.getMessage() + "'");
throw new ManagementException("HTTP service failed to start", e);
}
} else {
setStatusMessage(managerBean, "Embedded HTTP server configured not to start (http-service-port=0) or (jmx-manager-http-port=0)");
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class ManagementFunction method execute.
/**
* Actual function execution. It delegates task at managed node according to the request received.
*
* If any exception is encountered it will set the result to UNDEFINED
*/
public void execute(FunctionContext fc) {
boolean executedSuccessfully = false;
InternalCache cache = GemFireCacheImpl.getInstance();
Object[] functionArguments = (Object[]) fc.getArguments();
ObjectName objectName = (ObjectName) functionArguments[0];
String methodName = (String) functionArguments[1];
String[] signature = (String[]) functionArguments[2];
Object[] args = (Object[]) functionArguments[3];
String memberName = (String) functionArguments[4];
Object returnObj = null;
try {
final int nargs = (args == null) ? 0 : args.length;
if (methodName.startsWith("set") && methodName.length() > 3 && nargs == 1) {
Attribute attr = new Attribute(methodName.substring(3), args[0]);
mbeanServer.setAttribute(objectName, attr);
fc.getResultSender().lastResult((Serializable) null);
} else if (methodName.equals("addNotificationListener")) {
notificationHub.addHubNotificationListener(memberName, objectName);
fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
} else if (methodName.equals("removeNotificationListener")) {
notificationHub.removeHubNotificationListener(memberName, objectName);
fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
} else if (methodName.equals("getNotificationInfo")) {
fc.getResultSender().lastResult(mbeanServer.getMBeanInfo(objectName));
} else {
returnObj = mbeanServer.invoke(objectName, methodName, args, signature);
fc.getResultSender().lastResult((Serializable) returnObj);
}
executedSuccessfully = true;
} catch (InstanceNotFoundException e) {
if (cache != null && !cache.isClosed()) {
sendException(e, fc);
}
} catch (ReflectionException e) {
sendException(e, fc);
} catch (MBeanException e) {
sendException(e, fc);
} catch (NullPointerException e) {
sendException(e, fc);
} catch (Exception e) {
sendException(e, fc);
} finally {
if (!executedSuccessfully) {
if (cache == null || (cache != null && cache.isClosed())) {
Exception e = new Exception(ManagementStrings.MEMBER_IS_SHUTTING_DOWN.toLocalizedString());
sendException(e, fc);
// member is closing or invalid member
return;
}
}
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class RestAPIsWithSSLDUnitTest method startBridgeServer.
@SuppressWarnings("deprecation")
protected int startBridgeServer(String hostName, int restServicePort, final String locators, final String[] regions, final Properties sslProperties, boolean clusterLevel) {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
props.setProperty(START_DEV_REST_API, "true");
props.setProperty(HTTP_SERVICE_BIND_ADDRESS, hostName);
props.setProperty(HTTP_SERVICE_PORT, String.valueOf(restServicePort));
System.setProperty("javax.net.debug", "ssl,handshake");
props = configureSSL(props, sslProperties, clusterLevel);
DistributedSystem ds = getSystem(props);
InternalCache cache = (InternalCache) CacheFactory.create(ds);
cache.setReadSerialized(true);
AttributesFactory factory = new AttributesFactory();
factory.setEnableBridgeConflation(true);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
for (int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}
CacheServer server = cache.addCacheServer();
server.setPort(0);
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
remoteObjects.put(CACHE_KEY, cache);
return server.getPort();
}
Aggregations