Search in sources :

Example 1 with StorageInteractor

use of com.instaclustr.esop.impl.StorageInteractor in project esop by instaclustr.

the class ListOperation method run0.

@Override
protected void run0() throws Exception {
    assert restorerFactoryMap != null;
    assert objectMapper != null;
    request.storageLocation.validate();
    Path localPath = request.cacheDir;
    if (!request.skipDownload && !Files.exists(localPath)) {
        FileUtils.createDirectory(localPath);
    }
    if (request.resolveNodes) {
        assert cassandraJMXService != null;
        CassandraSimpleTopologyResult simpleTopology = new CassandraSimpleTopology(cassandraJMXService).act();
        request.storageLocation = StorageLocation.update(request.storageLocation, simpleTopology.getClusterName(), simpleTopology.getDc(), simpleTopology.getHostId());
    }
    try (final StorageInteractor interactor = restorerFactoryMap.get(request.storageLocation.storageProvider).createListingInteractor(request)) {
        interactor.update(request.storageLocation, new LocalFileRestorer(getForLocalListing(request, request.cacheDir, request.storageLocation), objectMapper));
        final AllManifestsReport report = AllManifestsReport.report(interactor.listManifests());
        filterFromTimestamp(report, request.fromTimestamp);
        filterLastN(report, request.lastN);
        if (request.toRequest) {
            request.response = report;
        } else {
            try (final PrintStream ps = getOutputStream(request)) {
                print(report, request, ps);
            }
        }
    } catch (final Exception ex) {
        logger.error("Unable to perform listing! - " + ex.getMessage(), ex);
        this.addError(Error.from(ex));
    }
}
Also used : Path(java.nio.file.Path) CassandraSimpleTopology(com.instaclustr.esop.topology.CassandraSimpleTopology) PrintStream(java.io.PrintStream) CassandraSimpleTopologyResult(com.instaclustr.esop.topology.CassandraSimpleTopology.CassandraSimpleTopologyResult) StorageInteractor(com.instaclustr.esop.impl.StorageInteractor) LocalFileRestorer(com.instaclustr.esop.local.LocalFileRestorer) AllManifestsReport(com.instaclustr.esop.impl.Manifest.AllManifestsReport)

Example 2 with StorageInteractor

use of com.instaclustr.esop.impl.StorageInteractor in project esop by instaclustr.

the class RemoveBackupOperation method run0.

@Override
protected void run0() throws Exception {
    assert restorerFactoryMap != null;
    assert objectMapper != null;
    request.validate(null);
    if (request.resolveNodes) {
        assert cassandraJMXService != null;
        CassandraSimpleTopologyResult simpleTopology = new CassandraSimpleTopology(cassandraJMXService).act();
        request.storageLocation = StorageLocation.update(request.storageLocation, simpleTopology.getClusterName(), simpleTopology.getDc(), simpleTopology.getHostId());
    }
    try (final StorageInteractor interactor = restorerFactoryMap.get(request.storageLocation.storageProvider).createDeletingInteractor(request)) {
        interactor.update(request.storageLocation, new LocalFileRestorer(getForLocalListing(request, request.cacheDir, request.storageLocation), objectMapper));
        for (final StorageLocation nodeLocation : getStorageLocations(interactor)) {
            logger.info("Looking for backups to delete for node {}", nodeLocation.nodePath());
            request.storageLocation = nodeLocation;
            interactor.update(nodeLocation, new LocalFileRestorer(getForLocalListing(request, request.cacheDir, request.storageLocation), objectMapper));
            final Optional<AllManifestsReport> reportOptional = getReport(interactor);
            if (!reportOptional.isPresent()) {
                logger.info("No backups found for {}", nodeLocation.nodePath());
                continue;
            }
            final AllManifestsReport report = reportOptional.get();
            logger.debug(report.toString());
            final List<ManifestReport> allBackupsToDelete = getBackupsToDelete(report);
            if (allBackupsToDelete.isEmpty()) {
                if (request.backupName != null) {
                    logger.info("There is not any {} backup to remove for node {}", request.backupName, nodeLocation);
                } else {
                    logger.info("There is not any backup to remove for node {}", nodeLocation);
                }
                continue;
            }
            logger.info("Removing backups for node {}: {}", nodeLocation.nodePath(), allBackupsToDelete.stream().map(mr -> mr.name).collect(Collectors.joining(",")));
            for (final ManifestReport mr : allBackupsToDelete) {
                interactor.delete(mr, request);
            }
        }
        if (!request.dry) {
            interactor.deleteTopology(request.backupName);
        } else {
            logger.info("Deletion of topology for {} was executed in dry mode", request.backupName);
        }
    } catch (final Exception ex) {
        logger.error("Unable to perform backup deletion! - " + ex.getMessage(), ex);
        this.addError(Error.from(ex));
    }
}
Also used : CassandraSimpleTopology(com.instaclustr.esop.topology.CassandraSimpleTopology) CassandraSimpleTopologyResult(com.instaclustr.esop.topology.CassandraSimpleTopology.CassandraSimpleTopologyResult) StorageInteractor(com.instaclustr.esop.impl.StorageInteractor) LocalFileRestorer(com.instaclustr.esop.local.LocalFileRestorer) ManifestReport(com.instaclustr.esop.impl.Manifest.ManifestReporter.ManifestReport) AllManifestsReport(com.instaclustr.esop.impl.Manifest.AllManifestsReport) StorageLocation(com.instaclustr.esop.impl.StorageLocation)

Aggregations

AllManifestsReport (com.instaclustr.esop.impl.Manifest.AllManifestsReport)2 StorageInteractor (com.instaclustr.esop.impl.StorageInteractor)2 LocalFileRestorer (com.instaclustr.esop.local.LocalFileRestorer)2 CassandraSimpleTopology (com.instaclustr.esop.topology.CassandraSimpleTopology)2 CassandraSimpleTopologyResult (com.instaclustr.esop.topology.CassandraSimpleTopology.CassandraSimpleTopologyResult)2 ManifestReport (com.instaclustr.esop.impl.Manifest.ManifestReporter.ManifestReport)1 StorageLocation (com.instaclustr.esop.impl.StorageLocation)1 PrintStream (java.io.PrintStream)1 Path (java.nio.file.Path)1