All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.chutneytesting.engine.domain.delegation.DelegationService Maven / Gradle / Ivy

The newest version!
/*
 * SPDX-FileCopyrightText: 2017-2024 Enedis
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 */

package com.chutneytesting.engine.domain.delegation;

import com.chutneytesting.action.spi.injectable.Target;
import com.chutneytesting.engine.domain.environment.TargetImpl;
import com.chutneytesting.engine.domain.execution.engine.StepExecutor;
import java.util.List;
import java.util.Optional;

public class DelegationService {

    private final StepExecutor localStepExecutor;
    private final DelegationClient delegationClient;

    public DelegationService(StepExecutor localStepExecutor,
                             DelegationClient delegationClient) {
        this.localStepExecutor = localStepExecutor;
        this.delegationClient = delegationClient;
    }

    public StepExecutor findExecutor(Optional target) {
        if (target.isEmpty() || target.get().name().isEmpty()) {
            return localStepExecutor;
        }

        List agents = ((TargetImpl) target.get()).agents;
        if (!agents.isEmpty()) {
            NamedHostAndPort nextAgent = agents.get(0);
            // TODO should we do that here ?
            agents.remove(0);
            return new RemoteStepExecutor(delegationClient, nextAgent);
        } else {
            return localStepExecutor;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy