Search in sources :

Example 21 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProfileRenameAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // but validate the new name
    try {
        FabricValidations.validateProfileName(newName);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    if (!version.hasProfile(profileName)) {
        System.out.println("Profile " + profileName + " not found.");
        return 1;
    } else if (version.hasProfile(newName)) {
        if (!force) {
            System.out.println("New name " + newName + " already exists. Use --force if you want to overwrite.");
            return null;
        }
    }
    Profiles.renameProfile(fabricService, version.getId(), profileName, newName, force);
    return null;
}
Also used : Version(io.fabric8.api.Version)

Example 22 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class EnsemblePasswordAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (!commit) {
        if (newPassword == null) {
            System.out.println(fabricService.getZookeeperPassword());
        } else {
            String zookeeperUrl = fabricService.getZookeeperUrl();
            String oldPassword = fabricService.getZookeeperPassword();
            System.out.println("Updating the password...");
            // Since we will be changing the password, create a new ZKClient that won't
            // be getting update by the password change.
            CuratorACLManager aclManager = new CuratorACLManager();
            CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(zookeeperUrl).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + oldPassword).getBytes()).sessionTimeoutMs(30000).build();
            curator.start();
            try {
                // Lets first adjust the acls so that the new password and old passwords work against the ZK paths.
                String digestedIdPass = DigestAuthenticationProvider.generateDigest("fabric:" + newPassword);
                aclManager.registerAcl("/fabric", "auth::acdrw,world:anyone:,digest:" + digestedIdPass + ":acdrw");
                aclManager.fixAcl(curator, "/fabric", true);
                // Ok now lets push out a config update of what the password is.
                curator.setData().forPath(ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath(), PasswordEncoder.encode(newPassword).getBytes(Charsets.UTF_8));
            } finally {
                curator.close();
            }
            // Refresh the default profile to cause all nodes to pickup the new password.
            ProfileService profileService = fabricService.adapt(ProfileService.class);
            for (String ver : profileService.getVersions()) {
                Version version = profileService.getVersion(ver);
                if (version != null) {
                    Profile profile = version.getProfile("default");
                    if (profile != null) {
                        Profiles.refreshProfile(fabricService, profile);
                    }
                }
            }
            System.out.println("");
            System.out.println("Password updated. Please wait a little while for the new password to");
            System.out.println("get delivered as a config update to all the fabric nodes. Once, the ");
            System.out.println("nodes all updated (nodes must be online), please run:");
            System.out.println("");
            System.out.println("  fabric:ensemble-password --commit ");
            System.out.println("");
        }
    } else {
        // Now lets connect with the new password and reset the ACLs so that the old password
        // does not work anymore.
        CuratorACLManager aclManager = new CuratorACLManager();
        CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(fabricService.getZookeeperUrl()).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + fabricService.getZookeeperPassword()).getBytes()).sessionTimeoutMs(30000).build();
        curator.start();
        try {
            aclManager.fixAcl(curator, "/fabric", true);
            System.out.println("Only the current password is allowed access to fabric now.");
        } finally {
            curator.close();
        }
    }
    return null;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorACLManager(io.fabric8.zookeeper.curator.CuratorACLManager)

Example 23 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ContainerListAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    Container[] containers = fabricService.getContainers();
    // filter unwanted containers, and split list into parent/child,
    // so we can sort the list as we want it
    containers = CommandUtils.filterContainers(containers, filter);
    // we want the list to be sorted
    containers = CommandUtils.sortContainers(containers);
    Version ver = null;
    if (version != null) {
        // limit containers to only with same version
        ver = profileService.getRequiredVersion(version);
    }
    if (verbose) {
        printContainersVerbose(containers, ver, System.out);
    } else {
        printContainers(containers, ver, System.out);
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) Version(io.fabric8.api.Version)

Example 24 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class MavenProxyServletSupport method readMvnCoordsPath.

protected static String readMvnCoordsPath(File file) throws Exception {
    JarFile jarFile = null;
    try {
        jarFile = new JarFile(file);
        String previous = null;
        String match = null;
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            String name = entry.getName();
            if (name.startsWith("META-INF/maven/") && name.endsWith("pom.properties")) {
                if (previous != null) {
                    throw new IllegalStateException(String.format("Duplicate pom.properties found: %s != %s", name, previous));
                }
                // check for dups
                previous = name;
                Properties props = new Properties();
                try (InputStream stream = jarFile.getInputStream(entry)) {
                    props.load(stream);
                }
                String groupId = props.getProperty("groupId");
                String artifactId = props.getProperty("artifactId");
                String version = props.getProperty("version");
                String packaging = Files.getFileExtension(file.getPath());
                match = String.format("%s/%s/%s/%s-%s.%s", groupId, artifactId, version, artifactId, version, packaging != null ? packaging : "jar");
            }
        }
        return match;
    } finally {
        if (jarFile != null) {
            jarFile.close();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) RuntimeProperties(io.fabric8.api.RuntimeProperties) Properties(java.util.Properties)

Example 25 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class MavenUploadProxyServlet method handleDeploy.

private void handleDeploy(HttpServletRequest req, UploadContext result) throws Exception {
    String profile = req.getParameter("profile");
    String version = req.getParameter("version");
    if (profile != null && version != null) {
        ProjectRequirements requirements = toProjectRequirements(result);
        requirements.setProfileId(profile);
        requirements.setVersion(version);
        DeployResults deployResults = addToProfile(requirements);
        LOGGER.info(String.format("Deployed artifact %s to profile: %s", result.toArtifact(), deployResults));
    }
}
Also used : DeployResults(io.fabric8.deployer.dto.DeployResults) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements)

Aggregations

Version (io.fabric8.api.Version)74 Profile (io.fabric8.api.Profile)70 File (java.io.File)52 Test (org.junit.Test)46 IOException (java.io.IOException)41 ArrayList (java.util.ArrayList)36 Container (io.fabric8.api.Container)35 HashMap (java.util.HashMap)34 ProfileService (io.fabric8.api.ProfileService)27 Map (java.util.Map)25 Git (org.eclipse.jgit.api.Git)22 FabricService (io.fabric8.api.FabricService)21 Version (org.osgi.framework.Version)21 ProfileBuilder (io.fabric8.api.ProfileBuilder)18 GitVersion (io.fabric8.api.commands.GitVersion)18 PatchException (io.fabric8.patch.management.PatchException)15 HashSet (java.util.HashSet)15 TreeMap (java.util.TreeMap)14 LinkedList (java.util.LinkedList)13 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)12