use of org.infinispan.server.core.BackupManager in project infinispan by infinispan.
the class BackupManagerImplTest method withBackupManager.
private <T> T withBackupManager(BiFunction<DefaultCacheManager, BackupManager, CompletionStage<T>> function) {
try (DefaultCacheManager cm = createManager()) {
BlockingManager blockingManager = cm.getGlobalComponentRegistry().getComponent(BlockingManager.class);
BackupManager backupManager = new BackupManagerImpl(blockingManager, cm, workingDir.toPath());
backupManager.init();
return await(function.apply(cm, backupManager));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.infinispan.server.core.BackupManager in project infinispan by infinispan.
the class Server method run.
public synchronized CompletableFuture<ExitStatus> run() {
CompletableFuture<ExitStatus> r = exitHandler.getExitFuture();
if (status == ComponentStatus.RUNNING) {
return r;
}
protocolServers = new ConcurrentHashMap<>(4);
try {
// Load any server extensions
extensions = new Extensions();
extensions.load(classLoader);
// Create the cache manager
cacheManager = new DefaultCacheManager(configurationBuilderHolder, false);
// Retrieve the server configuration
serverConfiguration = SecurityActions.getCacheManagerConfiguration(cacheManager).module(ServerConfiguration.class);
serverConfiguration.setServer(this);
// Initialize the data sources
dataSources = new HashMap<>();
InitialContext initialContext = new InitialContext();
for (DataSourceConfiguration dataSourceConfiguration : serverConfiguration.dataSources().values()) {
DataSource dataSource = DataSourceFactory.create(dataSourceConfiguration);
dataSources.put(dataSourceConfiguration.name(), dataSource);
initialContext.bind(dataSourceConfiguration.jndiName(), dataSource);
}
// Start the cache manager
SecurityActions.startCacheManager(cacheManager);
BasicComponentRegistry bcr = SecurityActions.getGlobalComponentRegistry(cacheManager).getComponent(BasicComponentRegistry.class.getName());
blockingManager = bcr.getComponent(BlockingManager.class).running();
serverStateManager = new ServerStateManagerImpl(this, cacheManager, bcr.getComponent(GlobalConfigurationManager.class).running());
bcr.registerComponent(ServerStateManager.class, serverStateManager, false);
ScheduledExecutorService timeoutExecutor = bcr.getComponent(KnownComponentNames.TIMEOUT_SCHEDULE_EXECUTOR, ScheduledExecutorService.class).running();
// BlockingManager of single container used for writing the global manifest, but this will need to change
// when multiple containers are supported by the server. Similarly, the default cache manager is used to create
// the clustered locks.
Path dataRoot = serverRoot.toPath().resolve(properties.getProperty(INFINISPAN_SERVER_DATA_PATH));
backupManager = new BackupManagerImpl(blockingManager, cacheManager, dataRoot);
backupManager.init();
// Register the task manager
taskManager = bcr.getComponent(TaskManager.class).running();
taskManager.registerTaskEngine(extensions.getServerTaskEngine(cacheManager));
// Initialize the OpenTracing integration
RequestTracer.start();
for (EndpointConfiguration endpoint : serverConfiguration.endpoints().endpoints()) {
// Start the protocol servers
SinglePortRouteSource routeSource = new SinglePortRouteSource();
Set<Route<? extends RouteSource, ? extends RouteDestination>> routes = ConcurrentHashMap.newKeySet();
endpoint.connectors().parallelStream().forEach(configuration -> {
try {
Class<? extends ProtocolServer> protocolServerClass = configuration.getClass().getAnnotation(ConfigurationFor.class).value().asSubclass(ProtocolServer.class);
ProtocolServer protocolServer = Util.getInstance(protocolServerClass);
protocolServer.setServerManagement(this, endpoint.admin());
if (configuration instanceof HotRodServerConfiguration) {
ElytronSASLAuthenticationProvider.init((HotRodServerConfiguration) configuration, serverConfiguration, timeoutExecutor);
} else if (configuration instanceof RestServerConfiguration) {
ElytronHTTPAuthenticator.init((RestServerConfiguration) configuration, serverConfiguration);
} else if (configuration instanceof RespServerConfiguration) {
ElytronRESPAuthenticator.init((RespServerConfiguration) configuration, serverConfiguration, blockingManager);
}
protocolServers.put(protocolServer.getName() + "-" + configuration.name(), protocolServer);
SecurityActions.startProtocolServer(protocolServer, configuration, cacheManager);
ProtocolServerConfiguration protocolConfig = protocolServer.getConfiguration();
if (protocolConfig.startTransport()) {
log.protocolStarted(protocolServer.getName(), configuration.socketBinding(), protocolConfig.host(), protocolConfig.port());
} else {
if (protocolServer instanceof HotRodServer) {
routes.add(new Route<>(routeSource, new HotRodServerRouteDestination(protocolServer.getName(), (HotRodServer) protocolServer)));
extensions.apply((HotRodServer) protocolServer);
} else if (protocolServer instanceof RestServer) {
routes.add(new Route<>(routeSource, new RestServerRouteDestination(protocolServer.getName(), (RestServer) protocolServer)));
} else if (protocolServer instanceof RespServer) {
routes.add(new Route<>(routeSource, new RespServerRouteDestination(protocolServer.getName(), (RespServer) protocolServer)));
}
log.protocolStarted(protocolServer.getName());
}
} catch (Throwable t) {
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
});
// Next we start the single-port endpoints
SinglePortRouterConfiguration singlePortRouter = endpoint.singlePortRouter();
SinglePortEndpointRouter endpointServer = new SinglePortEndpointRouter(singlePortRouter);
endpointServer.start(new RoutingTable(routes), cacheManager);
protocolServers.put("endpoint-" + endpoint.socketBinding(), endpointServer);
log.protocolStarted(endpointServer.getName(), singlePortRouter.socketBinding(), singlePortRouter.host(), singlePortRouter.port());
log.endpointUrl(Util.requireNonNullElse(cacheManager.getAddress(), "local"), singlePortRouter.ssl().enabled() ? "https" : "http", singlePortRouter.host(), singlePortRouter.port());
}
serverStateManager.start();
// Change status
this.status = ComponentStatus.RUNNING;
log.serverStarted(Version.getBrandName(), Version.getBrandVersion(), timeService.timeDuration(startTime, TimeUnit.MILLISECONDS));
} catch (Exception e) {
r.completeExceptionally(e);
}
r = r.handle((status, t) -> {
if (t != null) {
Server.log.serverFailedToStart(Version.getBrandName(), t);
}
localShutdown(status);
return null;
});
return r;
}
use of org.infinispan.server.core.BackupManager in project infinispan by infinispan.
the class ClusterResource method getAllBackupNames.
private CompletionStage<RestResponse> getAllBackupNames(RestRequest request) {
BackupManager backupManager = invocationHelper.getServer().getBackupManager();
Set<String> names = Security.doAs(request.getSubject(), (PrivilegedAction<Set<String>>) backupManager::getBackupNames);
return asJsonResponseFuture(Json.make(names));
}
use of org.infinispan.server.core.BackupManager in project infinispan by infinispan.
the class ContainerResource method getAllBackupNames.
private CompletionStage<RestResponse> getAllBackupNames(RestRequest request) {
BackupManager backupManager = invocationHelper.getServer().getBackupManager();
Set<String> names = backupManager.getBackupNames();
return asJsonResponseFuture(Json.make(names));
}
use of org.infinispan.server.core.BackupManager in project infinispan by infinispan.
the class BackupManagerResource method handleRestore.
static CompletionStage<RestResponse> handleRestore(String name, RestRequest request, BackupManager backupManager, TriFunction<String, Path, Json, CompletionStage<Void>> function) {
BackupManager.Status existingStatus = backupManager.getRestoreStatus(name);
if (existingStatus != BackupManager.Status.NOT_FOUND)
return responseFuture(CONFLICT);
Path path;
Json resourcesJson = Json.object();
MediaType contentType = request.contentType();
boolean uploadedBackup = contentType.match(MediaType.MULTIPART_FORM_DATA);
try {
if (uploadedBackup) {
FullHttpRequest nettyRequest = ((NettyRestRequest) request).getFullHttpRequest();
DefaultHttpDataFactory factory = new DefaultHttpDataFactory(true);
InterfaceHttpPostRequestDecoder decoder = new HttpPostMultipartRequestDecoder(factory, nettyRequest);
DiskFileUpload backup = (DiskFileUpload) decoder.getBodyHttpData("backup");
path = backup.getFile().toPath();
DiskAttribute resources = (DiskAttribute) decoder.getBodyHttpData("resources");
if (resources != null)
resourcesJson = Json.read(resources.getString());
} else if (contentType.match(MediaType.APPLICATION_JSON)) {
// Attempt to parse body as json
Json json = Json.read(request.contents().asString());
Json resources = json.at(RESOURCES_KEY);
if (resources != null)
resourcesJson = resources;
Json backupPath = json.at(LOCATION_KEY);
if (backupPath == null)
return responseFuture(BAD_REQUEST, "Required json attribute 'backup-location' not found");
path = Paths.get(backupPath.asString());
} else {
return responseFuture(UNSUPPORTED_MEDIA_TYPE);
}
function.apply(name, path, resourcesJson).whenComplete((Void, t) -> {
if (t != null) {
LOG.error(t);
}
if (uploadedBackup) {
try {
Files.delete(path);
} catch (IOException e) {
LOG.warnf(e, "Unable to delete uploaded backup file '%s'", path);
}
}
});
return responseFuture(ACCEPTED);
} catch (IOException e) {
LOG.error(e);
return responseFuture(INTERNAL_SERVER_ERROR, e.getMessage());
}
}
Aggregations