Search in sources :

Example 6 with Factory

use of io.fabric8.annotations.Factory in project docker-maven-plugin by fabric8io.

the class LogOutputSpecFactoryTest method createSpec.

private LogOutputSpec createSpec(String prefix) {
    LogOutputSpecFactory factory = new LogOutputSpecFactory(false, false, null);
    LogConfiguration logConfig = new LogConfiguration.Builder().prefix(prefix).build();
    RunImageConfiguration runConfig = new RunImageConfiguration.Builder().log(logConfig).build();
    ImageConfiguration imageConfiguration = new ImageConfiguration.Builder().alias(ALIAS).name(NAME).runConfig(runConfig).build();
    return factory.createSpec(CONTAINER_ID, imageConfiguration);
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) LogConfiguration(io.fabric8.maven.docker.config.LogConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration)

Example 7 with Factory

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

the class VerifyFeatureResolutionMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        Field field = URL.class.getDeclaredField("factory");
        field.setAccessible(true);
        field.set(null, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory());
    System.setProperty("karaf.home", "target/karaf");
    System.setProperty("karaf.data", "target/karaf/data");
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(8);
    Hashtable<String, String> properties = new Hashtable<>();
    if (additionalMetadata != null) {
        try (Reader reader = new FileReader(additionalMetadata)) {
            Properties metadata = new Properties();
            metadata.load(reader);
            for (Enumeration<?> e = metadata.propertyNames(); e.hasMoreElements(); ) {
                Object key = e.nextElement();
                Object val = metadata.get(key);
                properties.put(key.toString(), val.toString());
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to load additional metadata from " + additionalMetadata, e);
        }
    }
    DownloadManager manager;
    MavenResolver resolver;
    final Map<String, Repository> repositories;
    Map<String, Feature[]> repos = new HashMap<>();
    Map<String, Feature> allFeatures = new HashMap<>();
    try {
        resolver = MavenResolvers.createMavenResolver(null, properties, "org.ops4j.pax.url.mvn", repositorySystem);
        manager = DownloadManagers.createDownloadManager(resolver, executor);
        repositories = downloadRepositories(manager, descriptors).call();
        for (String repoUri : repositories.keySet()) {
            Feature[] features = repositories.get(repoUri).getFeatures();
            // Ack features to inline configuration files urls
            for (Feature feature : features) {
                for (BundleInfo bi : feature.getBundles()) {
                    String loc = bi.getLocation();
                    String nloc = null;
                    if (loc.contains("file:")) {
                        for (ConfigFile cfi : feature.getConfigurationFiles()) {
                            if (cfi.getFinalname().substring(1).equals(loc.substring(loc.indexOf("file:") + "file:".length()))) {
                                nloc = cfi.getLocation();
                            }
                        }
                    }
                    if (nloc != null) {
                        bi.setLocation(loc.substring(0, loc.indexOf("file:")) + nloc);
                    }
                }
                allFeatures.put(feature.getId(), feature);
            }
            repos.put(repoUri, features);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to load features descriptors", e);
    }
    List<Feature> featuresToTest = new ArrayList<>();
    if (verifyTransitive) {
        for (Feature[] features : repos.values()) {
            featuresToTest.addAll(Arrays.asList(features));
        }
    } else {
        for (String uri : descriptors) {
            featuresToTest.addAll(Arrays.asList(repos.get(uri)));
        }
    }
    if (features != null && !features.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (String feature : features) {
            if (sb.length() > 0) {
                sb.append("|");
            }
            String p = feature.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*");
            sb.append(p);
            if (!feature.contains("/")) {
                sb.append("/.*");
            }
        }
        Pattern pattern = Pattern.compile(sb.toString());
        for (Iterator<Feature> iterator = featuresToTest.iterator(); iterator.hasNext(); ) {
            Feature feature = iterator.next();
            String id = feature.getName() + "/" + feature.getVersion();
            if (!pattern.matcher(id).matches()) {
                iterator.remove();
            }
        }
    }
    for (String fmk : framework) {
        properties.put("feature.framework." + fmk, fmk);
    }
    List<Throwable> failures = new ArrayList<>();
    for (Feature feature : featuresToTest) {
        try {
            String id = feature.getName() + "/" + feature.getVersion();
            manager = DownloadManagers.createDownloadManager(resolver, executor);
            verifyResolution(manager, allFeatures, id, properties);
            getLog().info("Verification of feature " + id + " succeeded");
        } catch (Exception e) {
            getLog().warn(e.getMessage());
            failures.add(e);
            if ("first".equals(fail)) {
                throw e;
            }
        }
    }
    if ("end".equals(fail) && !failures.isEmpty()) {
        throw new MojoExecutionException("Verification failures", new MultiException("Verification failures", failures));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Reader(java.io.Reader) FileReader(java.io.FileReader) DeploymentAgent.getPrefixedProperties(io.fabric8.agent.DeploymentAgent.getPrefixedProperties) Properties(java.util.Properties) DownloadManager(io.fabric8.agent.download.DownloadManager) Feature(io.fabric8.agent.model.Feature) Field(java.lang.reflect.Field) BundleInfo(io.fabric8.agent.model.BundleInfo) FileReader(java.io.FileReader) Pattern(java.util.regex.Pattern) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ConfigFile(io.fabric8.agent.model.ConfigFile) Hashtable(java.util.Hashtable) IOException(java.io.IOException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) MultiException(io.fabric8.common.util.MultiException) Repository(io.fabric8.agent.model.Repository) MultiException(io.fabric8.common.util.MultiException)

Example 8 with Factory

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

the class CommandCollector method collect.

@Override
public List<Resource> collect(ResourceFactory factory) {
    List<Resource> result = new LinkedList<>();
    result.add(factory.createCommandResource("fabric:container-list"));
    if (fabricService != null) {
        Container[] containers = fabricService.getContainers();
        for (Container c : containers) {
            String name = c.getId();
            result.add(factory.createCommandResource("fabric:container-info " + name));
        }
    }
    result.add(factory.createCommandResource("zk:list -r -d"));
    // result.add(new CommandResource("each [1 2 3 ] { echo \"================ Execution $it ==============\"; dev:threads --dump ;  sleep 5000 }"));
    result.add(factory.createCommandResource("camel:context-list"));
    return result;
}
Also used : Container(io.fabric8.api.Container) Resource(io.fabric8.support.api.Resource) LinkedList(java.util.LinkedList)

Example 9 with Factory

use of io.fabric8.annotations.Factory in project alluxio by Alluxio.

the class ManagerProcessContext method applyMount.

/**
 * Apply mount hdfs command.
 *
 * @param req validated request
 * @return response
 */
public ApplyMountPointResponse.Payload applyMount(ApplyMountPointRequest req) {
    ApplyMountPointRequest.Payload p = req.getPayload();
    ApplyMountPointResponse.Payload.Builder resultBuilder = ApplyMountPointResponse.Payload.newBuilder();
    alluxio.hub.proto.MountPointInfo mountPointInfo = p.getNew();
    Map<String, String> properties = constructProp(mountPointInfo, false);
    MountPOptions.Builder optionBuilder = MountPOptions.newBuilder().setReadOnly(mountPointInfo.getReadOnly()).setShared(mountPointInfo.getShared()).putAllProperties(properties);
    boolean needToRemount = false;
    try {
        boolean needToMount = true;
        if (p.hasBefore()) {
            AlluxioURI originalMount = new AlluxioURI(p.getBefore().getAlluxioPath());
            if (originalMount.isRoot() && (!(p.getBefore().getAlluxioPath().equals(p.getNew().getAlluxioPath()) && p.getBefore().getUfsUri().equals(p.getNew().getUfsUri())))) {
                throw new IOException("Cannot change the mount location or ufs location of a root mount");
            }
            // if both mount uri and ufs uri has not changed
            if (originalMount.isRoot() || (p.getBefore().getAlluxioPath().equals(p.getNew().getAlluxioPath()) && p.getBefore().getUfsUri().equals(p.getNew().getUfsUri()))) {
                getFileSystem().updateMount(originalMount, optionBuilder.build());
                needToMount = false;
            } else {
                getFileSystem().unmount(originalMount);
                needToRemount = true;
            }
        }
        if (needToMount) {
            getFileSystem().mount(new AlluxioURI(mountPointInfo.getAlluxioPath()), new AlluxioURI(mountPointInfo.getUfsUri()), optionBuilder.build());
            needToRemount = false;
        }
        if (mountPointInfo.hasHdfsInfo() && mountPointInfo.getHdfsInfo().getEnableSync()) {
            getFileSystem().startSync(new AlluxioURI(mountPointInfo.getAlluxioPath()));
        }
        resultBuilder.setSuccess(true);
    } catch (Exception e) {
        if (needToRemount) {
            alluxio.hub.proto.MountPointInfo oldMountPoint = p.getBefore();
            MountPOptions.Builder oldOptionBuilder = MountPOptions.newBuilder().setReadOnly(oldMountPoint.getReadOnly()).setShared(oldMountPoint.getShared()).putAllProperties(constructProp(oldMountPoint, false));
            try {
                getFileSystem().mount(new AlluxioURI(oldMountPoint.getAlluxioPath()), new AlluxioURI(oldMountPoint.getUfsUri()), oldOptionBuilder.build());
            } catch (Exception ex) {
                LOG.warn("Failed to restore the mount point " + oldMountPoint.getAlluxioPath() + " to previous state");
                resultBuilder.addError(ValidationUtils.getErrorInfo(ex));
            }
        }
        LOG.warn("Failed applying mount settings due to " + ValidationUtils.getErrorInfo(e));
        resultBuilder.setSuccess(false);
        resultBuilder.addError(ValidationUtils.getErrorInfo(e));
        // =====================
        if (e instanceof InvalidPathException) {
            if (exceptionMatchesPattern(e, "mount point.*already exists.*")) {
                resultBuilder.setAdvice("Another file, directory, or mount point already exists at this" + " path. Check the Alluxio path you are mounting to again to make sure it" + " doesn't conflict with paths that already exist.");
            } else if (exceptionMatchesPattern(e, "mount point.*is a prefix of.*")) {
                resultBuilder.setAdvice("A mount point with a similar UFS URI is already mounted to" + " Alluxio. Make sure that your UFS URI doesn't have a namespace overlap with" + " another existing mount point");
            } else if (exceptionMatchesPattern(e, ".*path.*is invalid.*")) {
                resultBuilder.setAdvice("We couldn't parse your Alluxio path. Make sure to provide the" + " absolute path to where the new mount point should exist.");
            }
        } else if (e instanceof FileDoesNotExistException) {
            if (exceptionMatchesPattern(e, "file.*creation failed. component.*does not exist")) {
                resultBuilder.setAdvice("One of components in the path you are trying to mount to does" + " not exist. Make sure that all path components in the Alluxio namespace you" + " are trying to mount at exists, except for the last one.");
            }
        } else if (e instanceof AlluxioException) {
            if (exceptionMatchesPattern(e, ".*no underfilesystem factory found for.*")) {
                resultBuilder.setAdvice(String.format("Alluxio couldn't find a matching library with the" + " URI (%s) and version (%s) provided. This means that you're trying to mount a" + " URI with an unsupported scheme (<scheme>://) or, that Alluxio doesn't have" + " an available version of the UFS type you're trying to mount.", mountPointInfo.getUfsUri(), p.getNew().hasHdfsInfo() ? p.getNew().getHdfsInfo().getHdfsVersion() : "N/A"));
            } else if (exceptionMatchesPattern(e, ".*ufs path.*does not exist.*")) {
                resultBuilder.setAdvice("The UFS path you are trying to mount does not exist in the UFS." + " Please make sure the UFS path specified exists.");
            } else if (exceptionMatchesPattern(e, ".*java.net.unknownhostexception:.*")) {
                resultBuilder.setAdvice(String.format("We weren't able to resolve the hostname in your" + " HDFS uri %s. Please double check that you've typed the hostname correctly and" + " that the system DNS can resolve the hostname.", mountPointInfo.getUfsUri()));
            } else if (exceptionMatchesPattern(e, "call from.*to.*failed on connection exception.*")) {
                resultBuilder.setAdvice("We were able to resolve the hostname of your URI, but failed to" + " connect. Double check that the hostname and port are correct. Then, if it" + " still fails verify that there is no firewall blocking connections between" + " this machine and the UFS URI specified.");
            }
        }
    // END Advice handling
    // ===================
    }
    return resultBuilder.build();
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) MountPOptions(alluxio.grpc.MountPOptions) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) InvalidPathException(alluxio.exception.InvalidPathException) MountPointInfo(alluxio.wire.MountPointInfo) HDFSMountPointInfo(alluxio.hub.proto.HDFSMountPointInfo) ApplyMountPointRequest(alluxio.hub.proto.ApplyMountPointRequest) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 AlluxioURI (alluxio.AlluxioURI)1 AlluxioException (alluxio.exception.AlluxioException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 MountPOptions (alluxio.grpc.MountPOptions)1 ApplyMountPointRequest (alluxio.hub.proto.ApplyMountPointRequest)1 HDFSMountPointInfo (alluxio.hub.proto.HDFSMountPointInfo)1 MountPointInfo (alluxio.wire.MountPointInfo)1 GsonBuilder (com.google.gson.GsonBuilder)1 ByteString (com.google.protobuf.ByteString)1 DeploymentAgent.getPrefixedProperties (io.fabric8.agent.DeploymentAgent.getPrefixedProperties)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 BundleInfo (io.fabric8.agent.model.BundleInfo)1 ConfigFile (io.fabric8.agent.model.ConfigFile)1 Feature (io.fabric8.agent.model.Feature)1 Repository (io.fabric8.agent.model.Repository)1 Factory (io.fabric8.annotations.Factory)1