Search in sources :

Example 11 with Parser

use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.

the class ProfileDownloader method downloadProfile.

/**
 * Downloads the bundles, features and FABs for this profile.
 */
public void downloadProfile(Profile profile) throws Exception {
    if (listener != null) {
        listener.beforeDownloadProfile(profile);
    }
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    if (!profile.isOverlay()) {
        profile = profileService.getOverlayProfile(profile);
    }
    DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService, executorService);
    Set<String> bundles = new LinkedHashSet<String>();
    Set<Feature> features = new LinkedHashSet<Feature>();
    addMavenBundles(fabricService, profile, bundles, profile.getBundles());
    addMavenBundles(fabricService, profile, bundles, profile.getFabs());
    AgentUtils.addFeatures(features, fabricService, downloadManager, profile);
    Map<String, File> files = AgentUtils.downloadBundles(downloadManager, features, bundles, Collections.<String>emptySet(), !isDownloadFilesFromProfile());
    Set<Map.Entry<String, File>> entries = files.entrySet();
    for (Map.Entry<String, File> entry : entries) {
        String name = entry.getKey();
        File file = entry.getValue();
        if (processedFiles.add(file)) {
            String fileName = file.getName();
            String mvnCoords = getMavenCoords(name);
            File destFile;
            if (mvnCoords != null) {
                Parser parser = new Parser(mvnCoords);
                destFile = new File(target, parser.getArtifactPath());
            } else {
                destFile = new File(target, fileName);
            }
            if (force || !destFile.exists()) {
                LOG.info("Copying file: " + file + " to: " + destFile.getCanonicalPath());
                Files.copy(file, destFile);
                if (listener != null) {
                    listener.onCopyDone(profile, destFile);
                }
            }
        }
    }
    if (listener != null) {
        listener.afterDownloadProfile(profile);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Feature(io.fabric8.agent.model.Feature) Parser(io.fabric8.maven.util.Parser) ProfileService(io.fabric8.api.ProfileService) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with Parser

use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.

the class AgentUtils method getProfileArtifacts.

/**
 * Returns the location and parser map (i.e. the location and the parsed maven coordinates and artifact locations) of each bundle and feature
 */
public static Map<String, Parser> getProfileArtifacts(FabricService fabricService, Profile profile, Iterable<String> bundles, Iterable<Feature> features, Callback<String> nonMavenLocationCallback) {
    Set<String> locations = new HashSet<>();
    for (Feature feature : features) {
        List<BundleInfo> bundleList = feature.getBundles();
        if (bundleList == null) {
            LOGGER.warn("No bundles for feature " + feature);
        } else {
            for (BundleInfo bundle : bundleList) {
                locations.add(bundle.getLocation());
            }
        }
    }
    for (String bundle : bundles) {
        locations.add(bundle);
    }
    Map<String, Parser> artifacts = new HashMap<>();
    for (String location : locations) {
        try {
            if (location.contains("$")) {
                ProfileService profileService = fabricService.adapt(ProfileService.class);
                Profile overlay = profileService.getOverlayProfile(profile);
                location = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), location);
            }
            if (location.startsWith("mvn:") || location.contains(":mvn:")) {
                Parser parser = Parser.parsePathWithSchemePrefix(location);
                artifacts.put(location, parser);
            } else {
                if (nonMavenLocationCallback != null) {
                    nonMavenLocationCallback.call(location);
                }
            }
        } catch (MalformedURLException e) {
            LOGGER.error("Failed to parse bundle URL: " + location + ". " + e, e);
        }
    }
    return artifacts;
}
Also used : MalformedURLException(java.net.MalformedURLException) BundleInfo(io.fabric8.agent.model.BundleInfo) ProfileService(io.fabric8.api.ProfileService) HashMap(java.util.HashMap) Feature(io.fabric8.agent.model.Feature) Profile(io.fabric8.api.Profile) HashSet(java.util.HashSet) Parser(io.fabric8.maven.util.Parser)

Example 13 with Parser

use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.

the class JavaContainers method getJavaContainerArtifactsFiles.

public static Map<String, File> getJavaContainerArtifactsFiles(FabricService fabricService, List<Profile> profileList, DownloadManager downloadManager) throws Exception {
    Map<String, File> answer = new HashMap<String, File>();
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    for (Profile profile : profileList) {
        Profile overlay = profileService.getOverlayProfile(profile);
        Map<String, Parser> profileArtifacts = AgentUtils.getProfileArtifacts(fabricService, downloadManager, overlay);
        appendMavenDependencies(profileArtifacts, profile);
        Set<String> rawUrls = profileArtifacts.keySet();
        downloadArtifactUrls(downloadManager, rawUrls, answer);
    }
    return answer;
}
Also used : ProfileService(io.fabric8.api.ProfileService) HashMap(java.util.HashMap) File(java.io.File) Profile(io.fabric8.api.Profile) Parser(io.fabric8.maven.util.Parser)

Example 14 with Parser

use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.

the class StompProtocolDecoder method read_headers.

private Action<StompFrame> read_headers(final StompFrame frame) {
    final Ascii[] contentLengthValue = new Ascii[1];
    final ArrayList<StompFrame.HeaderEntry> headers = new ArrayList<StompFrame.HeaderEntry>(10);
    return new Action<StompFrame>() {

        public StompFrame apply() throws IOException {
            Buffer line = readUntil((byte) '\n', protocol.maxHeaderLength, "The maximum header length was exceeded");
            while (line != null) {
                line = chomp(line);
                if (line.length() > 0) {
                    if (protocol.maxHeaders != -1 && headers.size() > protocol.maxHeaders) {
                        throw new IOException("The maximum number of headers was exceeded");
                    }
                    try {
                        int seperatorIndex = indexOf(line, COLON_BYTE);
                        if (seperatorIndex < 0) {
                            throw new IOException("Header line missing separator [" + Ascii.ascii(line) + "]");
                        }
                        Buffer name = line.getBuffer(0, seperatorIndex);
                        if (trim) {
                            name = trim(name);
                        }
                        Buffer value = line.getBuffer(seperatorIndex + 1, line.length());
                        if (trim) {
                            value = trim(value);
                        }
                        StompFrame.HeaderEntry entry = new StompFrame.HeaderEntry(Ascii.ascii(name), Ascii.ascii(value));
                        if (entry.key.equals(CONTENT_LENGTH)) {
                            contentLengthValue[0] = entry.value;
                        }
                        headers.add(entry);
                    } catch (Exception e) {
                        throw new IOException("Unable to parser header line [" + line + "]");
                    }
                } else {
                    frame.setHeaders(headers);
                    Ascii contentLength = contentLengthValue[0];
                    if (contentLength != null) {
                        // Bless the client, he's telling us how much data to read in.
                        int length = 0;
                        try {
                            length = Integer.parseInt(contentLength.toString());
                        } catch (NumberFormatException e) {
                            throw new IOException("Specified content-length is not a valid integer");
                        }
                        if (protocol.maxDataLength != -1 && length > protocol.maxDataLength) {
                            throw new IOException("The maximum data length was exceeded");
                        }
                        nextDecodeAction = read_binary_body(frame, length);
                    } else {
                        nextDecodeAction = read_text_body(frame);
                    }
                    return nextDecodeAction.apply();
                }
                line = readUntil((byte) '\n', protocol.maxHeaderLength, "The maximum header length was exceeded");
            }
            return null;
        }
    };
}
Also used : Buffer(org.vertx.java.core.buffer.Buffer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Ascii(io.fabric8.gateway.handlers.detecting.protocol.Ascii)

Example 15 with Parser

use of io.fabric8.maven.util.Parser in project watchdog by isdream.

the class KubernetesListenerTest method main.

public static void main(String[] args) throws Exception {
    // Configure config = new Parser().parse("config/podWatcher.yaml");
    Configure config = new Parser().parse("config/namespaceWatcher.yaml");
    DefaultKubernetesClient client = new DefaultKubernetesClient("https://master.example:8443");
    Listener listener = new KubernetesListener();
    listener.start(client, config);
}
Also used : KubernetesListener(com.github.isdream.cwatcher.listeners.KubernetesListener) KubernetesListener(com.github.isdream.cwatcher.listeners.KubernetesListener) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Aggregations

Parser (io.fabric8.maven.util.Parser)12 Profile (io.fabric8.api.Profile)5 ProfileService (io.fabric8.api.ProfileService)5 HashMap (java.util.HashMap)5 File (java.io.File)4 Map (java.util.Map)4 Feature (io.fabric8.agent.model.Feature)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 BundleInfo (io.fabric8.agent.model.BundleInfo)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 KubernetesListener (com.github.isdream.cwatcher.listeners.KubernetesListener)1 OpenShiftListener (com.github.isdream.cwatcher.listeners.OpenShiftListener)1 ProfileVersionKey (io.fabric8.agent.commands.support.ProfileVersionKey)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Downloader (io.fabric8.agent.download.Downloader)1 StreamProvider (io.fabric8.agent.download.StreamProvider)1 MapUtils.addToMapSet (io.fabric8.agent.internal.MapUtils.addToMapSet)1