use of org.apache.geode.distributed.ServerLauncher in project geode by apache.
the class QueryResultData method setUp.
@Before
public void setUp() throws Exception {
AgentUtil agentUtil = new AgentUtil(GemFireVersion.getGemFireVersion());
if (agentUtil.findWarLocation("geode-web-api") == null) {
fail("unable to locate geode-web-api WAR file");
}
this.restServicePort = AvailablePortHelper.getRandomAvailableTCPPort();
try {
InetAddress addr = SocketCreator.getLocalHost();
this.hostName = addr.getHostName();
} catch (UnknownHostException ex) {
this.hostName = ManagementConstants.DEFAULT_HOST_NAME;
}
String workingDirectory = System.getProperty("geode.build.dir", System.getProperty("user.dir"));
ServerLauncher serverLauncher = new ServerLauncher.Builder().set(MCAST_PORT, "0").setServerBindAddress(this.hostName).setServerPort(0).set(START_DEV_REST_API, "true").set(HTTP_SERVICE_PORT, String.valueOf(this.restServicePort)).set(HTTP_SERVICE_BIND_ADDRESS, this.hostName).setPdxReadSerialized(true).setWorkingDirectory(workingDirectory).build();
serverLauncher.start();
this.baseURL = "http://" + this.hostName + ":" + this.restServicePort;
this.c = CacheFactory.getAnyInstance();
final AttributesFactory<String, String> attributesFactory = new AttributesFactory<>();
attributesFactory.setDataPolicy(DataPolicy.REPLICATE);
// Create region, customers
final RegionAttributes<String, String> regionAttributes = attributesFactory.create();
c.createRegion(CUSTOMER_REGION, regionAttributes);
// Create region, items
attributesFactory.setDataPolicy(DataPolicy.PARTITION);
c.createRegion(ITEM_REGION, regionAttributes);
// Create region, /orders
final AttributesFactory<Object, Object> af2 = new AttributesFactory<>();
af2.setDataPolicy(DataPolicy.PARTITION);
final RegionAttributes<Object, Object> rAttributes2 = af2.create();
c.createRegion(ORDER_REGION, rAttributes2);
// Create region, primitiveKVStore
final AttributesFactory<Object, Object> af1 = new AttributesFactory<>();
af1.setDataPolicy(DataPolicy.PARTITION);
final RegionAttributes<Object, Object> rAttributes = af1.create();
c.createRegion(PRIMITIVE_KV_STORE_REGION, rAttributes);
RegionFactory<String, Object> rf = c.createRegionFactory(RegionShortcut.REPLICATE);
rf.setDataPolicy(DataPolicy.EMPTY);
rf.setCacheLoader(new SimpleCacheLoader());
rf.setCacheWriter(new SampleCacheWriter());
rf.create(EMPTY_REGION);
// Register functions here
FunctionService.registerFunction(new GetAllEntries());
FunctionService.registerFunction(new GetRegions());
FunctionService.registerFunction(new PutKeyFunction());
FunctionService.registerFunction(new GetDeliveredOrders());
FunctionService.registerFunction(new AddFreeItemToOrders());
FunctionService.registerFunction(new NoArgumentFunction());
}
use of org.apache.geode.distributed.ServerLauncher in project geode by apache.
the class StatusServerCommand method statusServer.
@CliCommand(value = CliStrings.STATUS_SERVER, help = CliStrings.STATUS_SERVER__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result statusServer(@CliOption(key = CliStrings.STATUS_SERVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STATUS_SERVER__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STATUS_SERVER__PID, help = CliStrings.STATUS_SERVER__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STATUS_SERVER__DIR, help = CliStrings.STATUS_SERVER__DIR__HELP) final String workingDirectory) {
try {
if (StringUtils.isNotBlank(member)) {
if (isConnectedAndReady()) {
final MemberMXBean serverProxy = getMemberMXBean(member);
if (serverProxy != null) {
return ResultBuilder.createInfoResult(ServerLauncher.ServerState.fromJson(serverProxy.status()).toString());
} else {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_SERVER__NO_SERVER_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
}
} else {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Cache Server"));
}
} else {
final ServerLauncher serverLauncher = new ServerLauncher.Builder().setCommand(ServerLauncher.Command.STATUS).setDebug(isDebugging()).setDisableDefaultServer(true).setPid(pid).setWorkingDirectory(workingDirectory).build();
final ServerLauncher.ServerState status = serverLauncher.status();
return ResultBuilder.createInfoResult(status.toString());
}
} catch (IllegalArgumentException | IllegalStateException e) {
return ResultBuilder.createUserErrorResult(e.getMessage());
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STATUS_SERVER__GENERAL_ERROR_MESSAGE, toString(t, getGfsh().getDebug())));
}
}
use of org.apache.geode.distributed.ServerLauncher in project geode by apache.
the class StopServerCommand method stopServer.
@CliCommand(value = CliStrings.STOP_SERVER, help = CliStrings.STOP_SERVER__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result stopServer(@CliOption(key = CliStrings.STOP_SERVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STOP_SERVER__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STOP_SERVER__PID, help = CliStrings.STOP_SERVER__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STOP_SERVER__DIR, help = CliStrings.STOP_SERVER__DIR__HELP) final String workingDirectory) {
ServerLauncher.ServerState serverState;
try {
if (StringUtils.isNotBlank(member)) {
if (!isConnectedAndReady()) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STOP_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Cache Server"));
}
final MemberMXBean serverProxy = getMemberMXBean(member);
if (serverProxy != null) {
if (!serverProxy.isServer()) {
throw new IllegalStateException(CliStrings.format(CliStrings.STOP_SERVER__MEMBER_IS_NOT_SERVER_ERROR_MESSAGE, member));
}
serverState = ServerLauncher.ServerState.fromJson(serverProxy.status());
serverProxy.shutDownMember();
} else {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STOP_SERVER__NO_SERVER_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
}
} else {
final ServerLauncher serverLauncher = new ServerLauncher.Builder().setCommand(ServerLauncher.Command.STOP).setDebug(isDebugging()).setPid(pid).setWorkingDirectory(workingDirectory).build();
serverState = serverLauncher.status();
serverLauncher.stop();
}
if (AbstractLauncher.Status.ONLINE.equals(serverState.getStatus())) {
getGfsh().logInfo(String.format(CliStrings.STOP_SERVER__STOPPING_SERVER_MESSAGE, serverState.getWorkingDirectory(), serverState.getServiceLocation(), serverState.getMemberName(), serverState.getPid(), serverState.getLogFile()), null);
StopWatch stopWatch = new StopWatch(true);
while (serverState.isVmWithProcessIdRunning()) {
Gfsh.print(".");
if (stopWatch.elapsedTimeMillis() > WAITING_FOR_STOP_TO_MAKE_PID_GO_AWAY_TIMEOUT_MILLIS) {
break;
}
synchronized (this) {
TimeUnit.MILLISECONDS.timedWait(this, 500);
}
}
return ResultBuilder.createInfoResult(StringUtils.EMPTY);
} else {
return ResultBuilder.createUserErrorResult(serverState.toString());
}
} catch (IllegalArgumentException | IllegalStateException e) {
return ResultBuilder.createUserErrorResult(e.getMessage());
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STOP_SERVER__GENERAL_ERROR_MESSAGE, toString(t, getGfsh().getDebug())));
} finally {
Gfsh.redirectInternalJavaLoggers();
}
}
use of org.apache.geode.distributed.ServerLauncher in project geode by apache.
the class ShowMissingDiskStoresDUnitTest method restartServerAsync.
private AsyncInvocation restartServerAsync(MemberVM member) throws Exception {
String memberWorkingDir = member.getWorkingDir().getAbsolutePath();
int locatorPort = locator.getPort();
AsyncInvocation restart = member.invokeAsync(() -> {
ServerLauncher serverLauncher = new ServerLauncher.Builder().setWorkingDirectory(memberWorkingDir).setMemberName("server-1").set(LOCATORS, "localhost[" + locatorPort + "]").build();
serverLauncher.start();
});
return restart;
}
use of org.apache.geode.distributed.ServerLauncher in project geode by apache.
the class GFSnapshotDUnitTest method configureAndStartServer.
private void configureAndStartServer(final int locatorPort, final String serverHostName, final Properties properties) throws IOException {
final String memberName = getUniqueName() + "-server";
final File workingDirectory = temporaryFolder.newFolder(memberName);
final File pdxDirectory = temporaryFolder.newFolder(memberName + "-pdx");
final File diskStoreDirectory = temporaryFolder.newFolder(memberName + "-disk");
ServerLauncher.Builder builder = new ServerLauncher.Builder();
for (String propertyName : properties.stringPropertyNames()) {
builder.set(propertyName, properties.getProperty(propertyName));
}
ServerLauncher serverLauncher = builder.set("locators", serverHostName + "[" + locatorPort + "]").setMemberName(memberName).set("log-level", "config").setHostNameForClients(serverHostName).setServerBindAddress(serverHostName).setServerPort(0).setWorkingDirectory(workingDirectory.getCanonicalPath()).setPdxDiskStore("pdxDS").setPdxPersistent(true).build();
serverLauncher.start();
Cache cache = CacheFactory.getAnyInstance();
cache.createDiskStoreFactory().setDiskDirsAndSizes(new File[] { pdxDirectory }, new int[] { 16000 }).create("pdxDS");
cache.createDiskStoreFactory().setDiskDirsAndSizes(new File[] { diskStoreDirectory }, new int[] { 16000 }).create("diskStore");
RegionFactory<Object, Object> regionFactory = cache.createRegionFactory();
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE).setScope(Scope.DISTRIBUTED_ACK).setDiskStoreName("diskStore").create("TestRegion");
}
Aggregations