use of com.netflix.titus.api.common.LeaderActivationListener in project titus-control-plane by Netflix.
the class LeaderActivationCoordinator method activate.
private void activate() {
if (!stateRef.compareAndSet(State.Awaiting, State.ElectedLeader)) {
logger.debug("Activation process has been already attempted. Component is in: state={}", stateRef.get());
return;
}
logger.info("Starting the leader activation process (activating {} services)...", services.size());
Stopwatch allStart = Stopwatch.createStarted();
List<LeaderActivationListener> activated = new ArrayList<>();
for (LeaderActivationListener service : services) {
String serviceName = service.getClass().getSimpleName();
logger.info("Activating service {}...", serviceName);
Stopwatch serviceStart = Stopwatch.createStarted();
try {
service.activate();
activated.add(service);
logger.info("Service {} started in {}", serviceName, serviceStart.elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
logger.error("Service activation failure. Rolling back", e);
this.activatedServices = activated;
try {
deactivate();
} finally {
deactivationCallback.accept(e);
}
return;
}
}
this.activatedServices = activated;
this.activationTimestamp = clock.wallTime();
logger.info("Activation process finished in: {}", DateTimeExt.toTimeUnitString(allStart.elapsed(TimeUnit.MILLISECONDS)));
}
use of com.netflix.titus.api.common.LeaderActivationListener in project titus-control-plane by Netflix.
the class LeaderActivationCoordinator method deactivate.
private void deactivate() {
this.activationTimestamp = -1;
State current = stateRef.getAndSet(State.Deactivated);
if (current == State.Awaiting) {
logger.info("Deactivating non-leader member");
return;
}
if (current == State.Deactivated) {
logger.debug("Already deactivated");
return;
}
logger.info("Stopping the elected leader (deactivating {} services)...", activatedServices.size());
Stopwatch allStart = Stopwatch.createStarted();
List<LeaderActivationListener> deactivationList = new ArrayList<>(activatedServices);
Collections.reverse(deactivationList);
activatedServices.clear();
for (LeaderActivationListener service : deactivationList) {
String serviceName = service.getClass().getSimpleName();
logger.info("Deactivating service {}...", serviceName);
Stopwatch serviceStart = Stopwatch.createStarted();
try {
service.deactivate();
logger.info("Service {} stopped in {}", serviceName, serviceStart.elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
logger.error("Failed to deactivate service: {}", serviceName);
}
}
logger.info("Deactivation process finished in: {}", DateTimeExt.toTimeUnitString(allStart.elapsed(TimeUnit.MILLISECONDS)));
}
Aggregations