class LoadBalancerStepDefinitions {

    @When("^detach (\\d+) instances from loadbalancer$")
    public LoadBalancerStepDefinitions deRegisterInstances(int numInstances) {
        List<EC2InstanceTO> instances = executionStateCache.getInstances();

        if (instances == null || instances.isEmpty())
        {
            throw new RuntimeException("No Instances are vailable");
        }

        logger.info("number of available instances: " + instances.size());
        if (numInstances > instances.size()) {
            numInstances = instances.size();
        }

        List<EC2InstanceTO> instanceList = instances;
        if (instanceList.size() != numInstances) {
            instanceList = instances.subList(0, numInstances);
        }

        logger.info("Detaching instances " + instanceList.stream().map(x -> x.getInstanceId()).collect(Collectors.toList())
                + " from " + executionStateCache.getLoadBalancerName());

        loadBalancerRaider.deregisterInstancesFromLoadBalancer(executionStateCache.getLoadBalancerName(), Ec2Utils.generateInstanceIdList(instanceList));
        executionStateCache.addDeregisteredInstance(instanceList);

        return this;
    }

    public  LoadBalancerStepDefinitions();

}