Search in sources :

Example 26 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class WatcherSpringContext method addPath.

// Implementation
// -------------------------------------------------------------------------
protected void addPath(Path path) {
    String url = null;
    try {
        url = toUrlString(path);
    } catch (MalformedURLException e) {
        LOG.warn("Ignored path " + path + " due to: " + e, e);
    }
    if (url != null) {
        FileSystemXmlApplicationContext context = contextMap.get(url);
        if (context != null) {
            try {
                LOG.info("Refreshing context at path " + path + " context " + context);
                context.refresh();
            } catch (Exception e) {
                LOG.warn("Failed to refresh context at " + path + " context " + context + ". " + e, e);
            }
        } else {
            context = createContext(path, url);
            if (context != null) {
                contextMap.put(url, context);
                try {
                    LOG.info("Starting context at path " + path + " context " + context);
                    context.start();
                } catch (Exception e) {
                    LOG.warn("Failed to start context at " + path + " context " + context + ". " + e, e);
                }
            }
        }
    }
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) MalformedURLException(java.net.MalformedURLException) PathHelper.toUrlString(io.fabric8.watcher.PathHelper.toUrlString) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 27 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class FileWatcher method unscan.

private void unscan(final Path file) throws IOException {
    if (isMatchesFile(file)) {
        Processor processor = getProcessor();
        if (processor != null) {
            processor.onRemove(file);
        }
        lastModified = System.currentTimeMillis();
    } else {
        // lets find all the files that now no longer exist
        List<Path> files = new ArrayList<Path>(processedMap.keySet());
        for (Path path : files) {
            if (!Files.exists(path)) {
                LOGGER.debug("File has been deleted: " + path);
                processedMap.remove(path);
                if (isMatchesFile(path)) {
                    Processor processor = getProcessor();
                    if (processor != null) {
                        processor.onRemove(path);
                    }
                    fireListeners(path, ENTRY_DELETE);
                    lastModified = System.currentTimeMillis();
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Processor(io.fabric8.watcher.Processor) ArrayList(java.util.ArrayList)

Example 28 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class FileWatcherMapping method init.

public void init() throws IOException {
    if (camelContext == null) {
        throw new IllegalArgumentException("CamelContext must be configured on " + this);
    }
    mapper = new DozerBeanMapper();
    setFileMatchPattern("glob:META-INF/services/dozer/*.xml");
    setProcessor(new Processor() {

        public void process(Path path) {
            addOrUpdateMapping(path);
        }

        public void onRemove(Path path) {
            removeMapping(path);
        }
    });
    super.init();
    LOG.info("Watching directory " + getRoot() + " for Dozer XML Mapping file changes");
}
Also used : Path(java.nio.file.Path) Processor(io.fabric8.watcher.Processor) DozerBeanMapper(org.dozer.DozerBeanMapper)

Example 29 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class ZookeeperPortService method findUsedPortByHost.

private Set<Integer> findUsedPortByHost(Container container, Lease existingLease) {
    assertValid();
    String ip = container.getIp();
    assertValidIp(container, ip);
    Set<Integer> ports = new HashSet<Integer>();
    String path = ZkPath.PORTS_IP.getPath(ip);
    Lease lease = null;
    try {
        if (existingLease != null) {
            lease = existingLease;
        } else {
            lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
        }
        if (lease != null) {
            createDefault(curator.get(), path, "");
            String boundPorts = getStringData(curator.get(), path);
            if (boundPorts != null && !boundPorts.isEmpty()) {
                for (String port : boundPorts.split(" ")) {
                    try {
                        ports.add(Integer.parseInt(port.trim()));
                    } catch (NumberFormatException ex) {
                    // ignore
                    }
                }
            }
        } else {
            throw new FabricException("Could not acquire port lock");
        }
    } catch (InterruptedException ex) {
        cleanUpDirtyZKNodes(interProcessLock);
        throw FabricException.launderThrowable(ex);
    } catch (Exception ex) {
        throw FabricException.launderThrowable(ex);
    } finally {
        if (existingLease == null) {
            releaseLock(lease);
        }
    }
    return ports;
}
Also used : Lease(org.apache.curator.framework.recipes.locks.Lease) FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException) HashSet(java.util.HashSet)

Example 30 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class FabricCxfRegistrationHandler method registerApiEndpoint.

protected void registerApiEndpoint(Container container, ObjectName oName, String address, boolean started) {
    String actualEndpointUrl = null;
    try {
        String url;
        String id = container.getId();
        if (isFullAddress(address)) {
            url = toPublicAddress(id, address);
        } else {
            String cxfBus = getCxfServletPath(oName);
            url = "${zk:" + id + "/http}" + cxfBus + address;
        }
        actualEndpointUrl = ZooKeeperUtils.getSubstitutedData(curator.get(), url);
        // lets assume these locations are hard coded
        // may be nice to discover from JMX one day
        String apiDocPath = "/api-docs";
        String wsdlPath = "?wsdl";
        String wadlPath = "?_wadl";
        Version version = container.getVersion();
        String versionId = version != null ? version.getId() : null;
        String json = "{\"id\":" + JsonHelper.jsonEncodeString(id) + ", \"container\":" + JsonHelper.jsonEncodeString(id) + ", \"version\":" + JsonHelper.jsonEncodeString(versionId) + ", \"services\":[" + JsonHelper.jsonEncodeString(url) + "]" + ", \"objectName\":" + JsonHelper.jsonEncodeString(oName.toString()) + "";
        boolean rest = false;
        if (booleanAttribute(oName, "isWADL")) {
            rest = true;
            json += ", \"wadl\":" + JsonHelper.jsonEncodeString(wadlPath);
        }
        if (booleanAttribute(oName, "isSwagger")) {
            rest = true;
            json += ", \"apidocs\":" + JsonHelper.jsonEncodeString(apiDocPath);
        }
        if (booleanAttribute(oName, "isWSDL")) {
            json += ", \"wsdl\":" + JsonHelper.jsonEncodeString(wsdlPath);
        }
        json += "}";
        String path = getPath(container, oName, address, rest);
        LOGGER.info("Registered CXF API at " + path + " JSON: " + json);
        if (!started && !rest) {
            LOGGER.warn("Since the CXF service isn't started, this could really be a REST endpoint rather than WSDL at " + path);
        }
        registeredZkPaths.add(path);
        registeredUrls.put(oName.toString(), address);
        ZooKeeperUtils.setData(curator.get(), path, json, CreateMode.EPHEMERAL);
    } catch (Exception e) {
        LOGGER.error("Failed to register API endpoint for {}.", actualEndpointUrl, e);
    }
}
Also used : Version(io.fabric8.api.Version) URISyntaxException(java.net.URISyntaxException) BadBinaryOpValueExpException(javax.management.BadBinaryOpValueExpException) BadStringOperationException(javax.management.BadStringOperationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MalformedURLException(java.net.MalformedURLException) BadAttributeValueExpException(javax.management.BadAttributeValueExpException) IOException(java.io.IOException) InvalidApplicationException(javax.management.InvalidApplicationException)

Aggregations

Test (org.junit.Test)45 File (java.io.File)41 IOException (java.io.IOException)34 ArrayList (java.util.ArrayList)18 PathTestUtil.createTmpFile (io.fabric8.maven.docker.util.PathTestUtil.createTmpFile)17 HashMap (java.util.HashMap)12 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)11 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)11 Path (java.nio.file.Path)11 FabricService (io.fabric8.api.FabricService)10 RuntimeProperties (io.fabric8.api.RuntimeProperties)9 Properties (java.util.Properties)9 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)8 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)8 InputStream (java.io.InputStream)8 Path (javax.ws.rs.Path)8 HttpProxyRule (io.fabric8.gateway.model.HttpProxyRule)7 NodeState (io.fabric8.groups.NodeState)7 URISyntaxException (java.net.URISyntaxException)7 List (java.util.List)6