class RequestHandlerUtils extends AbstractRestHandler {

    protected Optional<String> getServiceInstanceIdForInstanceGroup(String requestScope, ServiceInstancesRequest sir) {
        if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) {
            RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList();
            if (relatedInstances != null) {
                for (RelatedInstanceList relatedInstanceList : relatedInstances) {
                    RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
                    if (relatedInstance.getModelInfo().getModelType() == ModelType.service) {
                        return Optional.ofNullable(relatedInstance.getInstanceId());
                    }
                }
            }
        }
        return Optional.empty();
    }

}