com.instaclustr.cassandra.sidecar.operations.decommission.DecommissionOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-sidecar Show documentation
Show all versions of cassandra-sidecar Show documentation
Sidecar for Apache Cassandra
package com.instaclustr.cassandra.sidecar.operations.decommission;
import java.time.Instant;
import java.util.UUID;
import javax.inject.Inject;
import javax.inject.Provider;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.inject.assistedinject.Assisted;
import com.instaclustr.cassandra.CassandraVersion;
import com.instaclustr.operations.FunctionWithEx;
import com.instaclustr.operations.Operation;
import jmx.org.apache.cassandra.service.CassandraJMXService;
import jmx.org.apache.cassandra.service.cassandra3.StorageServiceMBean;
import jmx.org.apache.cassandra.service.cassandra4.Cassandra4StorageServiceMBean;
public class DecommissionOperation extends Operation {
private final CassandraJMXService cassandraJMXService;
private final Provider cassandraVersionProvider;
@Inject
public DecommissionOperation(final CassandraJMXService cassandraJMXService,
final Provider cassandraVersionProvider,
@Assisted final DecommissionOperationRequest request) {
super(request);
this.cassandraJMXService = cassandraJMXService;
this.cassandraVersionProvider = cassandraVersionProvider;
}
// this constructor is not meant to be instantiated manually
// and it fulfills the purpose of deserialisation from JSON string to an Operation object, currently just for testing purposes
@JsonCreator
private DecommissionOperation(@JsonProperty("type") final String type,
@JsonProperty("id") final UUID id,
@JsonProperty("creationTime") final Instant creationTime,
@JsonProperty("state") final State state,
@JsonProperty("failureCause") final Throwable failureCause,
@JsonProperty("progress") final float progress,
@JsonProperty("startTime") final Instant startTime,
@JsonProperty("force") final Boolean force) {
super(type, id, creationTime, state, failureCause, progress, startTime, new DecommissionOperationRequest(type, force));
cassandraJMXService = null;
cassandraVersionProvider = null;
}
@Override
protected void run0() throws Exception {
assert cassandraJMXService != null;
assert cassandraVersionProvider != null;
if (cassandraVersionProvider.get().getMajor() == 4) {
cassandraJMXService.doWithCassandra4StorageServiceMBean(new FunctionWithEx() {
@Override
public Void apply(final Cassandra4StorageServiceMBean object) throws Exception {
object.decommission(request.force == null ? true : request.force);
return null;
}
});
} else {
cassandraJMXService.doWithStorageServiceMBean(new FunctionWithEx() {
@Override
public Void apply(final StorageServiceMBean object) throws Exception {
object.decommission();
return null;
}
});
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy