Search in sources :

Example 1 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class InPlaceRestorationStrategy method getNodeTopology.

private NodeTopology getNodeTopology(final Restorer restorer, final RestoreOperationRequest request) {
    try {
        final String topologyFile = format("topology/%s", request.snapshotTag);
        final String topology = restorer.downloadFileToString(Paths.get(topologyFile), fileName -> fileName.contains(topologyFile));
        final ClusterTopology clusterTopology = objectMapper.readValue(topology, ClusterTopology.class);
        // by translating, we get proper node id (uuid) so we fetch the right node in remote bucket
        return clusterTopology.translateToNodeTopology(request.storageLocation.nodeId);
    } catch (final Exception ex) {
        throw new IllegalStateException(format("Unable to resolve node hostId to restore to for request %s", request), ex);
    }
}
Also used : ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology)

Example 2 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class BaseBackupOperationCoordinator method coordinate.

@Override
public void coordinate(final Operation<BackupOperationRequest> operation) {
    final BackupOperationRequest request = operation.request;
    logger.info(request.toString());
    try {
        assert cassandraJMXService != null;
        assert backuperFactoryMap != null;
        assert bucketServiceFactoryMap != null;
        assert objectMapper != null;
        if (!request.skipBucketVerification) {
            try (final BucketService bucketService = bucketServiceFactoryMap.get(request.storageLocation.storageProvider).createBucketService(request)) {
                bucketService.checkBucket(request.storageLocation.bucket, request.createMissingBucket);
            }
        }
        final CassandraData cassandraData = CassandraData.parse(request.dataDirs.get(0));
        cassandraData.setDatabaseEntitiesFromRequest(request.entities);
        final List<String> tokens = new CassandraTokens(cassandraJMXService).act();
        logger.info("Tokens {}", tokens);
        if (!Snapshots.snapshotContainsTimestamp(operation.request.snapshotTag)) {
            if (operation.request.schemaVersion == null) {
                operation.request.schemaVersion = new CassandraSchemaVersion(cassandraJMXService).act();
            }
            operation.request.snapshotTag = resolveSnapshotTag(operation.request, System.currentTimeMillis());
        }
        logger.info("Taking snapshot with name {}", request.snapshotTag);
        new TakeSnapshotOperation(cassandraJMXService, new TakeSnapshotOperationRequest(request.entities, request.snapshotTag), cassandraVersionProvider).run0();
        Snapshots.hashSpec = hashSpec;
        final Snapshots snapshots = Snapshots.parse(request.dataDirs, request.snapshotTag);
        final Optional<Snapshot> snapshot = snapshots.get(request.snapshotTag);
        if (!snapshot.isPresent()) {
            throw new IllegalStateException(format("There is not any snapshot of tag %s", request.snapshotTag));
        }
        final Manifest manifest = Manifest.from(snapshot.get());
        manifest.setSchemaVersion(request.schemaVersion);
        manifest.setTokens(tokens);
        // manifest
        final Path localManifestPath = getLocalManifestPath(request.snapshotTag);
        Manifest.write(manifest, localManifestPath, objectMapper);
        manifest.setManifest(getManifestAsManifestEntry(localManifestPath));
        try (final Backuper backuper = backuperFactoryMap.get(request.storageLocation.storageProvider).createBackuper(request)) {
            final List<ManifestEntry> manifestEntries = manifest.getManifestEntries();
            Session<UploadUnit> uploadSession = null;
            try {
                uploadSession = uploadTracker.submit(backuper, operation, manifestEntries, request.snapshotTag, operation.request.concurrentConnections);
                uploadSession.waitUntilConsideredFinished();
                uploadTracker.cancelIfNecessary(uploadSession);
                final List<UploadUnit> failedUnits = uploadSession.getFailedUnits();
                if (!failedUnits.isEmpty()) {
                    final String message = failedUnits.stream().map(unit -> unit.getManifestEntry().objectKey.toString()).collect(Collectors.joining(","));
                    logger.error(message);
                    throw new IOException(format("Unable to upload some files successfully: %s", message));
                }
            } finally {
                uploadTracker.removeSession(uploadSession);
                uploadSession = null;
            }
            if (operation.request.uploadClusterTopology) {
                // here we will upload all topology because we do not know what restore might look like (what dc a restorer will restore against if any)
                final ClusterTopology topology = new CassandraClusterTopology(cassandraJMXService, null).act();
                ClusterTopology.upload(backuper, topology, objectMapper, operation.request.snapshotTag);
            }
        } finally {
            manifest.cleanup();
        }
    } catch (final Exception ex) {
        operation.addError(Error.from(ex));
    } finally {
        final ClearSnapshotOperation cso = new ClearSnapshotOperation(cassandraJMXService, new ClearSnapshotOperationRequest(request.snapshotTag));
        try {
            cso.run0();
        } catch (final Exception ex) {
            operation.addErrors(cso.errors);
        }
    }
}
Also used : CassandraData(com.instaclustr.esop.impl.CassandraData) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Error(com.instaclustr.operations.Operation.Error) Manifest.getManifestAsManifestEntry(com.instaclustr.esop.impl.Manifest.getManifestAsManifestEntry) Provider(javax.inject.Provider) HashSpec(com.instaclustr.esop.impl.hash.HashSpec) OperationCoordinator(com.instaclustr.operations.OperationCoordinator) LoggerFactory(org.slf4j.LoggerFactory) Manifest.getLocalManifestPath(com.instaclustr.esop.impl.Manifest.getLocalManifestPath) BackuperFactory(com.instaclustr.esop.guice.BackuperFactory) Map(java.util.Map) Session(com.instaclustr.esop.impl.AbstractTracker.Session) CassandraClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology) Path(java.nio.file.Path) CassandraData(com.instaclustr.esop.impl.CassandraData) BucketServiceFactory(com.instaclustr.esop.guice.BucketServiceFactory) BucketService(com.instaclustr.esop.impl.BucketService) Backuper(com.instaclustr.esop.impl.backup.Backuper) CassandraSchemaVersion(com.instaclustr.esop.impl.interaction.CassandraSchemaVersion) Logger(org.slf4j.Logger) UploadTracker(com.instaclustr.esop.impl.backup.UploadTracker) Operation(com.instaclustr.operations.Operation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Manifest(com.instaclustr.esop.impl.Manifest) Snapshot(com.instaclustr.esop.impl.Snapshots.Snapshot) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ClearSnapshotOperationRequest(com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation.ClearSnapshotOperationRequest) List(java.util.List) Snapshots(com.instaclustr.esop.impl.Snapshots) UploadUnit(com.instaclustr.esop.impl.backup.UploadTracker.UploadUnit) TakeSnapshotOperationRequest(com.instaclustr.esop.impl.backup.coordination.TakeSnapshotOperation.TakeSnapshotOperationRequest) CassandraVersion(com.instaclustr.cassandra.CassandraVersion) Optional(java.util.Optional) BackupOperationRequest(com.instaclustr.esop.impl.backup.BackupOperationRequest) CassandraTokens(com.instaclustr.esop.impl.interaction.CassandraTokens) ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) CassandraJMXService(jmx.org.apache.cassandra.service.CassandraJMXService) ClearSnapshotOperationRequest(com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation.ClearSnapshotOperationRequest) TakeSnapshotOperationRequest(com.instaclustr.esop.impl.backup.coordination.TakeSnapshotOperation.TakeSnapshotOperationRequest) CassandraClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology) ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) CassandraSchemaVersion(com.instaclustr.esop.impl.interaction.CassandraSchemaVersion) UploadUnit(com.instaclustr.esop.impl.backup.UploadTracker.UploadUnit) CassandraClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology) CassandraTokens(com.instaclustr.esop.impl.interaction.CassandraTokens) Backuper(com.instaclustr.esop.impl.backup.Backuper) Snapshots(com.instaclustr.esop.impl.Snapshots) Manifest.getLocalManifestPath(com.instaclustr.esop.impl.Manifest.getLocalManifestPath) Path(java.nio.file.Path) BucketService(com.instaclustr.esop.impl.BucketService) IOException(java.io.IOException) Manifest(com.instaclustr.esop.impl.Manifest) IOException(java.io.IOException) Snapshot(com.instaclustr.esop.impl.Snapshots.Snapshot) BackupOperationRequest(com.instaclustr.esop.impl.backup.BackupOperationRequest) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Manifest.getManifestAsManifestEntry(com.instaclustr.esop.impl.Manifest.getManifestAsManifestEntry)

Example 3 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class CassandraClusterTopologyTest method testNoDcFiltering.

@Test
public void testNoDcFiltering() throws Exception {
    final ClusterTopology topology = getClusterTopology();
    ClusterTopology filtered = ClusterTopology.filter(topology, Collections.emptyList());
    assertEquals(topology, filtered);
}
Also used : ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) Test(org.testng.annotations.Test)

Example 4 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class CassandraClusterTopologyTest method invalidDcs.

@Test
public void invalidDcs() throws Exception {
    final ClusterTopology topology = getClusterTopology();
    final Set<String> invalidDcs = ClusterTopology.sanitizeDcs(" dc3   ,").stream().filter(dc -> !topology.getDcs().contains(dc)).collect(toSet());
    assertFalse(invalidDcs.isEmpty());
}
Also used : InetAddress(java.net.InetAddress) InetAddress.getByName(java.net.InetAddress.getByName) Assert(org.testng.Assert) Assert.assertEquals(org.testng.Assert.assertEquals) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) UUID(java.util.UUID) Assert.assertFalse(org.testng.Assert.assertFalse) Collections(java.util.Collections) ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) Collectors.toSet(java.util.stream.Collectors.toSet) ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) Test(org.testng.annotations.Test)

Example 5 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class CassandraClusterTopologyTest method getClusterTopology.

private ClusterTopology getClusterTopology() throws Exception {
    ClusterTopology clusterTopology = new ClusterTopology();
    clusterTopology.endpointRacks = new HashMap<InetAddress, String>() {

        {
            put(getByName("127.0.0.1"), "rack1");
            put(getByName("127.0.0.2"), "rack2");
            put(getByName("127.0.0.3"), "rack3");
            put(getByName("127.0.0.4"), "rack1");
            put(getByName("127.0.0.5"), "rack2");
            put(getByName("127.0.0.6"), "rack3");
        }
    };
    clusterTopology.hostnames = new HashMap<InetAddress, String>() {

        {
            put(getByName("127.0.0.1"), "host1");
            put(getByName("127.0.0.2"), "host2");
            put(getByName("127.0.0.3"), "host3");
            put(getByName("127.0.0.4"), "host4");
            put(getByName("127.0.0.5"), "host5");
            put(getByName("127.0.0.6"), "host6");
        }
    };
    clusterTopology.endpoints = new HashMap<InetAddress, UUID>() {

        {
            put(getByName("127.0.0.1"), uuid1);
            put(getByName("127.0.0.2"), uuid2);
            put(getByName("127.0.0.3"), uuid3);
            put(getByName("127.0.0.4"), uuid4);
            put(getByName("127.0.0.5"), uuid5);
            put(getByName("127.0.0.6"), uuid6);
        }
    };
    clusterTopology.endpointDcs = new HashMap<InetAddress, String>() {

        {
            put(getByName("127.0.0.1"), "dc1");
            put(getByName("127.0.0.2"), "dc1");
            put(getByName("127.0.0.3"), "dc1");
            put(getByName("127.0.0.4"), "dc2");
            put(getByName("127.0.0.5"), "dc2");
            put(getByName("127.0.0.6"), "dc2");
        }
    };
    clusterTopology.clusterName = "abc";
    clusterTopology.timestamp = System.currentTimeMillis();
    clusterTopology.schemaVersion = UUID.randomUUID().toString();
    return clusterTopology;
}
Also used : ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Aggregations

ClusterTopology (com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology)9 InetAddress (java.net.InetAddress)4 Test (org.testng.annotations.Test)4 UUID (java.util.UUID)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Backuper (com.instaclustr.esop.impl.backup.Backuper)2 CassandraSchemaVersion (com.instaclustr.esop.impl.interaction.CassandraSchemaVersion)2 IOException (java.io.IOException)2 String.format (java.lang.String.format)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 MoreObjects (com.google.common.base.MoreObjects)1 CassandraInteraction (com.instaclustr.cassandra.CassandraInteraction)1 CassandraVersion (com.instaclustr.cassandra.CassandraVersion)1