class DefaultAgentManagementService implements AgentManagementService {

    @Override
    public Completable scaleUp(String instanceGroupId, int scaleUpCount) {
        if (!configuration.isInstanceGroupUpdateCapacityEnabled()) {
            return Completable.complete();
        }
        return Observable.fromCallable(() -> agentCache.getInstanceGroup(instanceGroupId))
                .flatMap(instanceGroup -> {
                            Completable cloudUpdate = instanceCloudConnector.scaleUp(instanceGroup.getId(), scaleUpCount);
                            Completable cacheUpdate = agentCache.updateInstanceGroupStoreAndSyncCloud(
                                    instanceGroup.getId(),
                                    ig -> ig.toBuilder().withDesired(ig.getDesired() + scaleUpCount).build()
                            ).toCompletable();
                            return cloudUpdate.concatWith(cacheUpdate).toObservable();
                        }
                )
                .toCompletable();
    }

    @Inject public  DefaultAgentManagementService(AgentManagementConfiguration configuration,
                                         @Named(KUBE_SCHEDULER_INSTANCE_GROUP_PREDICATE) Predicate<AgentInstanceGroup> kubeSchedulerInstanceGroupPredicate,
                                         InstanceCloudConnector instanceCloudConnector,
                                         AgentCache AgentCache,
                                         ServerInfoResolver serverInfoResolver,
                                         TitusRuntime titusRuntime);

}