class BBInputSetupUtils {

    public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId)
            throws Exception {
        AAIPluralResourceUri uri =
                AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().instanceGroup(instanceGroupId))
                        .relatedTo(Types.SERVICE_INSTANCES.getFragment());
        Optional<ServiceInstances> serviceInstances = injectionHelper.getAaiClient().get(ServiceInstances.class, uri);
        ServiceInstance serviceInstance = null;
        if (!serviceInstances.isPresent()) {
            logger.debug("No ServiceInstances were found");
            return Optional.empty();
        } else {
            if (serviceInstances.get().getServiceInstance().isEmpty()) {
                throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
            } else if (serviceInstances.get().getServiceInstance().size() > 1) {
                String message = String.format("Mulitple service instances were found for instance-group-id: %s.",
                        instanceGroupId);
                throw new MultipleObjectsFoundException(message);
            } else {
                serviceInstance = serviceInstances.get().getServiceInstance().get(0);
            }
            return Optional.of(serviceInstance);
        }
    }

}