Search in sources :

Example 1 with KubeMembershipExecutor

use of com.netflix.titus.ext.kube.clustermembership.connector.KubeMembershipExecutor in project titus-control-plane by Netflix.

the class KubeRegistrationActions method registerLocal.

public static Mono<Function<KubeClusterState, KubeClusterState>> registerLocal(KubeContext context, KubeClusterState kubeClusterState, Function<ClusterMember, ClusterMembershipRevision<ClusterMember>> selfUpdate) {
    ClusterMember localMember = kubeClusterState.getLocalMemberRevision().getCurrent();
    ClusterMembershipRevision<ClusterMember> newRevision = setRegistrationStatus(selfUpdate.apply(localMember), true);
    KubeMembershipExecutor membershipExecutor = context.getKubeMembershipExecutor();
    Mono<ClusterMembershipRevision<ClusterMember>> monoAction;
    if (kubeClusterState.isRegistered()) {
        monoAction = membershipExecutor.updateLocal(newRevision).onErrorResume(e -> {
            if (!KubeUtils.is4xx(e)) {
                return Mono.error(e);
            }
            int status = KubeUtils.getHttpStatusCode(e);
            if (status == 404) {
                return membershipExecutor.createLocal(newRevision);
            }
            // Bad or stale data record. Remove it first and than register.
            return membershipExecutor.removeMember(newRevision.getCurrent().getMemberId()).then(membershipExecutor.createLocal(newRevision));
        });
    } else {
        monoAction = membershipExecutor.createLocal(newRevision).onErrorResume(e -> {
            if (!KubeUtils.is4xx(e)) {
                return Mono.error(e);
            }
            // Bad or stale data record. Remove it first and than register.
            return membershipExecutor.removeMember(newRevision.getCurrent().getMemberId()).then(membershipExecutor.createLocal(newRevision));
        });
    }
    return monoAction.onErrorMap(KubeUtils::toConnectorException).map(update -> currentState -> currentState.setMustRegister(true).setLocalClusterMemberRevision(update, true));
}
Also used : KubeUtils(com.netflix.titus.ext.kube.clustermembership.connector.transport.KubeUtils) KubeMembershipExecutor(com.netflix.titus.ext.kube.clustermembership.connector.KubeMembershipExecutor) ClusterMember(com.netflix.titus.api.clustermembership.model.ClusterMember) Mono(reactor.core.publisher.Mono) KubeClusterState(com.netflix.titus.ext.kube.clustermembership.connector.KubeClusterState) Function(java.util.function.Function) ClusterMembershipRevision(com.netflix.titus.api.clustermembership.model.ClusterMembershipRevision) KubeContext(com.netflix.titus.ext.kube.clustermembership.connector.KubeContext) ClusterMember(com.netflix.titus.api.clustermembership.model.ClusterMember) KubeMembershipExecutor(com.netflix.titus.ext.kube.clustermembership.connector.KubeMembershipExecutor) ClusterMembershipRevision(com.netflix.titus.api.clustermembership.model.ClusterMembershipRevision)

Aggregations

ClusterMember (com.netflix.titus.api.clustermembership.model.ClusterMember)1 ClusterMembershipRevision (com.netflix.titus.api.clustermembership.model.ClusterMembershipRevision)1 KubeClusterState (com.netflix.titus.ext.kube.clustermembership.connector.KubeClusterState)1 KubeContext (com.netflix.titus.ext.kube.clustermembership.connector.KubeContext)1 KubeMembershipExecutor (com.netflix.titus.ext.kube.clustermembership.connector.KubeMembershipExecutor)1 KubeUtils (com.netflix.titus.ext.kube.clustermembership.connector.transport.KubeUtils)1 Function (java.util.function.Function)1 Mono (reactor.core.publisher.Mono)1