Search in sources :

Example 46 with InvalidPathException

use of java.nio.file.InvalidPathException in project open-kilda by telstra.

the class FlowValidationService method validateFlow.

/**
 * Validate flow.
 */
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries, List<SwitchGroupEntries> switchGroupEntries) throws FlowNotFoundException, SwitchNotFoundException {
    Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>();
    int rulesCount = 0;
    int metersCount = 0;
    for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) {
        SwitchMeterEntries switchMeters = switchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
        SwitchGroupEntries switchGroup = switchGroupEntries.stream().filter(groupEntries -> switchRulesEntries.getSwitchId().equals(groupEntries.getSwitchId())).findFirst().orElse(null);
        List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, switchGroup);
        switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
        rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()).map(List::size).orElse(0);
        metersCount += Optional.ofNullable(switchMeters).map(SwitchMeterEntries::getMeterEntries).map(List::size).orElse(0);
    }
    Optional<Flow> foundFlow = flowRepository.findById(flowId);
    if (!foundFlow.isPresent()) {
        throw new FlowNotFoundException(flowId);
    }
    Flow flow = foundFlow.get();
    if (flow.getForwardPath() == null) {
        throw new InvalidPathException(flowId, "Forward path was not returned.");
    }
    if (flow.getReversePath() == null) {
        throw new InvalidPathException(flowId, "Reverse path was not returned.");
    }
    List<FlowValidationResponse> flowValidationResponse = new ArrayList<>();
    List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath());
    flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount));
    List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath());
    flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount));
    if (flow.getProtectedForwardPath() != null) {
        List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath());
        flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount));
    }
    if (flow.getProtectedReversePath() != null) {
        List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath());
        flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount));
    }
    return flowValidationResponse;
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) HashMap(java.util.HashMap) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) InvalidPathException(java.nio.file.InvalidPathException) Flow(org.openkilda.model.Flow) SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) ArrayList(java.util.ArrayList) List(java.util.List)

Example 47 with InvalidPathException

use of java.nio.file.InvalidPathException in project elasticsearch by elastic.

the class TranslogTests method randomNonTranslogPatternString.

private String randomNonTranslogPatternString(int min, int max) {
    String string;
    boolean validPathString;
    do {
        validPathString = false;
        string = randomRealisticUnicodeOfCodepointLength(randomIntBetween(min, max));
        try {
            final Path resolved = translogDir.resolve(string);
            // some strings (like '/' , '..') do not refer to a file, which we this method should return
            validPathString = resolved.getFileName() != null;
        } catch (InvalidPathException ex) {
        // some FS don't like our random file names -- let's just skip these random choices
        }
    } while (Translog.PARSE_STRICT_ID_PATTERN.matcher(string).matches() || validPathString == false);
    return string;
}
Also used : Path(java.nio.file.Path) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) InvalidPathException(java.nio.file.InvalidPathException)

Example 48 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testNTFSFileDataStreamAlias.

/**
     * NTFS Alternative Data / File Streams.
     * <p>
     * See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364404(v=vs.85).aspx
     * @throws Exception failed test
     */
@Test
public void testNTFSFileDataStreamAlias() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path path = dir.resolve("testfile");
    Files.createFile(path);
    try (Resource base = newResource(dir.toFile())) {
        Resource resource = base.addPath("testfile");
        assertThat("resource.alias", resource, hasNoAlias());
        assertThat("resource.uri.alias", newResource(resource.getURI()), hasNoAlias());
        assertThat("resource.file.alias", newResource(resource.getFile()), hasNoAlias());
        try {
            // Attempt to reference same file, but via NTFS DATA stream
            Resource alias = base.addPath("testfile::$DATA");
            if (alias.exists()) {
                assumeThat(alias.getURI().getScheme(), is("http"));
                // If it exists, it must be an alias
                assertThat("resource.alias", alias, isAliasFor(resource));
                assertThat("resource.uri.alias", newResource(alias.getURI()), isAliasFor(resource));
                assertThat("resource.file.alias", newResource(alias.getFile()), isAliasFor(resource));
            }
        } catch (InvalidPathException e) {
            // NTFS filesystem streams are unsupported on some platforms.
            assumeNoException(e);
        }
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Example 49 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testNTFSFileEncodedDataStreamAlias.

/**
     * NTFS Alternative Data / File Streams.
     * <p>
     * See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364404(v=vs.85).aspx
     * @throws Exception failed test
     */
@Test
public void testNTFSFileEncodedDataStreamAlias() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path path = dir.resolve("testfile");
    Files.createFile(path);
    try (Resource base = newResource(dir.toFile())) {
        Resource resource = base.addPath("testfile");
        assertThat("resource.alias", resource, hasNoAlias());
        assertThat("resource.uri.alias", newResource(resource.getURI()), hasNoAlias());
        assertThat("resource.file.alias", newResource(resource.getFile()), hasNoAlias());
        try {
            // Attempt to reference same file, but via NTFS DATA stream (encoded addPath version) 
            Resource alias = base.addPath("testfile::%24DATA");
            if (alias.exists()) {
                // If it exists, it must be an alias
                assertThat("resource.alias", alias, isAliasFor(resource));
                assertThat("resource.uri.alias", newResource(alias.getURI()), isAliasFor(resource));
                assertThat("resource.file.alias", newResource(alias.getFile()), isAliasFor(resource));
            }
        } catch (InvalidPathException e) {
            // NTFS filesystem streams are unsupported on some platforms.
            assumeNoException(e);
        }
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Example 50 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testAddInitialDoubleSlash.

@Test
public void testAddInitialDoubleSlash() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path basePath = dir.resolve("base");
    FS.ensureDirExists(basePath);
    Path filePath = basePath.resolve("foo.txt");
    Files.createFile(filePath);
    try (Resource base = newResource(basePath.toFile())) {
        assertThat("Exists: " + basePath, base.exists(), is(true));
        assertThat("Alias: " + basePath, base, hasNoAlias());
        Resource r = base.addPath("//foo.txt");
        assertThat("getURI()", r.getURI().toASCIIString(), containsString("//foo.txt"));
        assertThat("isAlias()", r.isAlias(), is(true));
        assertThat("getAlias()", r.getAlias(), notNullValue());
        assertThat("getAlias()", r.getAlias().toASCIIString(), containsString("/foo.txt"));
        assertThat("Exists: " + r, r.exists(), is(true));
    } catch (InvalidPathException e) {
    // Exception is acceptable
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)111 Path (java.nio.file.Path)58 IOException (java.io.IOException)30 File (java.io.File)17 URL (java.net.URL)15 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 ArrayList (java.util.ArrayList)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 BufferedReader (java.io.BufferedReader)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4