@Override
    public List<Intent> compile(SinglePointToMultiPointIntent intent,
                                List<Intent> installable) {
        Set<Link> links = new HashSet<>();

        final boolean allowMissingPaths = intentAllowsPartialFailure(intent);
        boolean hasPaths = false;
        boolean missingSomePaths = false;

        for (ConnectPoint egressPoint : intent.egressPoints()) {
            if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) {
                // Do not need to look for paths, since ingress and egress
                // devices are the same.
                if (deviceService.isAvailable(egressPoint.deviceId())) {
                    hasPaths = true;
                } else {
                    missingSomePaths = true;
                }
                continue;
            }

            Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());

            if (path != null) {
                hasPaths = true;
                links.addAll(path.links());
            } else {
                missingSomePaths = true;
            }
        }

        // Allocate bandwidth if a bandwidth constraint is set
        ConnectPoint ingressCP = intent.filteredIngressPoint().connectPoint();
        List<ConnectPoint> egressCPs =
                intent.filteredEgressPoints().stream()
                        .map(fcp -> fcp.connectPoint())
                        .collect(Collectors.toList());

        List<ConnectPoint> pathCPs =
                links.stream()
                     .flatMap(l -> Stream.of(l.src(), l.dst()))
                     .collect(Collectors.toList());

        pathCPs.add(ingressCP);
        pathCPs.addAll(egressCPs);

        allocateBandwidth(intent, pathCPs);

        if (!hasPaths) {
            throw new IntentException("Cannot find any path between ingress and egress points.");
        } else if (!allowMissingPaths && missingSomePaths) {
            throw new IntentException("Missing some paths between ingress and egress points.");
        }

        Intent result = LinkCollectionIntent.builder()
                .appId(intent.appId())
                .key(intent.key())
                .selector(intent.selector())
                .treatment(intent.treatment())
                .links(links)
                .filteredIngressPoints(ImmutableSet.of(intent.filteredIngressPoint()))
                .filteredEgressPoints(intent.filteredEgressPoints())
                .priority(intent.priority())
                .applyTreatmentOnEgress(true)
                .constraints(intent.constraints())
                .resourceGroup(intent.resourceGroup())
                .build();

        return Collections.singletonList(result);
    }
@Test
    public void testPartialFailureConstraintFailure() {
        FilteredConnectPoint ingress =
                new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1));

        Set<FilteredConnectPoint> egress = ImmutableSet.of(
                new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2)),
                new FilteredConnectPoint(new ConnectPoint(DID_5, PORT_2)));

        SinglePointToMultiPointIntent intent =
                makeIntent(ingress, egress);

        String[] hops = {S3};

        SinglePointToMultiPointIntentCompiler compiler =
                makeCompiler(null,
                             new IntentTestsMocks.FixedMP2MPMockPathService(hops),
                             null);
        assertThat(compiler, is(notNullValue()));

        intentException.expect(IntentException.class);

        List<Intent> result = compiler.compile(intent, null);
        assertThat(result, null);
    }