Search in sources :

Example 91 with FabricService

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

the class ContainerRemoveProfileAction method doExecute.

protected Object doExecute() throws Exception {
    FabricValidations.validateContainerName(container);
    // Do not validate profile names, because we want to be able to remove non-existent profiles.
    Container cont = FabricCommand.getContainer(fabricService, container);
    // allow to remove non-existing profiles
    List<String> profileIds = new ArrayList<>();
    for (Profile profile : FabricCommand.getProfiles(fabricService, cont.getVersion(), profiles)) {
        profileIds.add(profile.getId());
    }
    cont.removeProfiles(profileIds.toArray(new String[profileIds.size()]));
    return null;
}
Also used : Container(io.fabric8.api.Container) ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile)

Example 92 with FabricService

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

the class ContainerRollbackAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    FabricValidations.validateContainerNames(containerIds);
    // check and validate version
    Version version = profileService.getRequiredVersion(this.version);
    if (containerIds == null || containerIds.isEmpty()) {
        if (all) {
            containerIds = new ArrayList<String>();
            for (Container container : fabricService.getContainers()) {
                containerIds.add(container.getId());
            }
        } else {
            containerIds = Arrays.asList(fabricService.getCurrentContainer().getId());
        }
    } else {
        if (all) {
            throw new IllegalArgumentException("Can not use --all with a list of containers simultaneously");
        }
    }
    List<Container> toRollback = new ArrayList<Container>();
    List<Container> same = new ArrayList<Container>();
    for (String containerName : containerIds) {
        Container container = FabricCommand.getContainer(fabricService, containerName);
        // check first that all can rollback
        int num = ContainerUpgradeSupport.canRollback(version, container);
        if (num < 0) {
            throw new IllegalArgumentException("Container " + container.getId() + " has already lower version " + container.getVersion().getId() + " than the requested version " + version.getId() + " to rollback.");
        } else if (num == 0) {
            // same version
            same.add(container);
        } else {
            // needs rollback
            toRollback.add(container);
        }
    }
    // report same version
    for (Container container : same) {
        System.out.println("Container " + container.getId() + " is already version " + version.getId());
    }
    // report and do rollbacks
    for (Container container : toRollback) {
        Version oldVersion = container.getVersion();
        // rollback version first
        container.setVersion(version);
        log.info("Rolled back container {} from {} to {}", new Object[] { container.getId(), oldVersion.getId(), version.getId() });
        System.out.println("Rolled back container " + container.getId() + " from version " + oldVersion.getId() + " to " + version.getId());
    }
    if (all) {
        fabricService.setDefaultVersionId(version.getId());
        System.out.println("Changed default version to " + version.getId());
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList)

Example 93 with FabricService

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

the class ContainerUpgradeAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    FabricValidations.validateContainerNames(containerIds);
    // check and validate version
    Version version = profileService.getRequiredVersion(this.version);
    if (containerIds == null || containerIds.isEmpty()) {
        if (all) {
            containerIds = new ArrayList<String>();
            for (Container container : fabricService.getContainers()) {
                containerIds.add(container.getId());
            }
        } else {
            containerIds = Arrays.asList(fabricService.getCurrentContainer().getId());
        }
    } else {
        if (all) {
            throw new IllegalArgumentException("Can not use --all with a list of containers simultaneously");
        }
    }
    List<Container> toUpgrade = new ArrayList<Container>();
    List<Container> same = new ArrayList<Container>();
    for (String containerName : containerIds) {
        Container container = FabricCommand.getContainer(fabricService, containerName);
        // check first that all can upgrade
        int num = ContainerUpgradeSupport.canUpgrade(version, container);
        if (num < 0) {
            throw new IllegalArgumentException("Container " + container.getId() + " already has a higher version " + container.getVersion() + " than the requested version " + version.getId() + ".");
        } else if (num == 0) {
            // same version
            same.add(container);
        } else {
            // needs upgrade
            toUpgrade.add(container);
        }
    }
    // report same version
    for (Container container : same) {
        System.out.println("Container " + container.getId() + " is already at version " + version.getId());
    }
    // report and do upgrades
    for (Container container : toUpgrade) {
        Version oldVersion = container.getVersion();
        // upgrade version first
        container.setVersion(version);
        // get the profile for version 1.1
        log.info("Upgraded container {} from {} to {}", new Object[] { container.getId(), oldVersion.getId(), version.getId() });
        System.out.println("Upgraded container " + container.getId() + " from version " + oldVersion.getId() + " to " + version.getId());
    }
    if (all) {
        fabricService.setDefaultVersionId(version.getId());
        System.out.println("Changed default version to " + version.getId());
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList)

Example 94 with FabricService

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

the class ProfileDynamicJaxbCompiler method recompile.

protected void recompile() {
    LOG.debug("Looking for XSDs to recompile");
    Set<String> urls = new TreeSet<String>();
    FabricService fabric = getFabricService();
    Container container = fabric.getCurrentContainer();
    String versionId = container.getVersion().getId();
    List<String> profileIds = Containers.overlayProfiles(container);
    Collection<String> names = listFiles(versionId, profileIds, schemaPath);
    for (String name : names) {
        if (name.endsWith(".xsd")) {
            String prefix = schemaPath;
            if (Strings.isNotBlank(prefix)) {
                prefix += "/";
            }
            urls.add("profile:" + prefix + name);
        }
    }
    LOG.info("Recompiling XSDs at URLs: " + urls);
    startedFlag.set(false);
    ClassLoader classLoader = AriesFrameworkUtil.getClassLoader(bundleContext.getBundle());
    if (classLoader == null) {
        classLoader = getClass().getClassLoader();
    }
    DynamicXJC xjc = new DynamicXJC(classLoader);
    xjc.setSchemaUrls(new ArrayList<String>(urls));
    compileResults = xjc.compileSchemas();
    if (handler != null) {
        handler.onCompileResults(compileResults);
    }
    if (introspector != null) {
        introspector.setClassLoaderProvider("dynamic.jaxb", new ClassLoaderProvider() {

            @Override
            public ClassLoader getClassLoader() {
                return compileResults.getClassLoader();
            }
        });
    }
}
Also used : Container(io.fabric8.api.Container) TreeSet(java.util.TreeSet) FabricService(io.fabric8.api.FabricService) ClassLoaderProvider(io.hawt.util.introspect.ClassLoaderProvider) DynamicXJC(io.fabric8.jaxb.dynamic.DynamicXJC)

Example 95 with FabricService

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

the class FabricServiceImpl method substituteConfigurations.

/**
 * Performs substitution to configuration based on the registered {@link PlaceholderResolver} instances.
 */
public Map<String, Map<String, String>> substituteConfigurations(final Map<String, Map<String, String>> configurations) {
    final Map<String, PlaceholderResolver> resolversSnapshot = new HashMap<String, PlaceholderResolver>(placeholderResolvers);
    // Check that all resolvers are available
    Set<String> requiredSchemes = getSchemesForProfileConfigurations(configurations);
    Set<String> availableSchemes = resolversSnapshot.keySet();
    if (!availableSchemes.containsAll(requiredSchemes)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Missing Placeholder Resolvers:");
        for (String scheme : requiredSchemes) {
            if (!availableSchemes.contains(scheme)) {
                sb.append(" ").append(scheme);
            }
        }
        throw new FabricException(sb.toString());
    }
    final Map<String, Map<String, String>> mutableConfigurations = new HashMap<>();
    for (Entry<String, Map<String, String>> entry : configurations.entrySet()) {
        String key = entry.getKey();
        Map<String, String> value = new HashMap<>(entry.getValue());
        mutableConfigurations.put(key, value);
    }
    final FabricService fabricService = this;
    for (Map.Entry<String, Map<String, String>> entry : mutableConfigurations.entrySet()) {
        final String pid = entry.getKey();
        Map<String, String> props = entry.getValue();
        Map<String, String> original = new HashMap<>(props);
        for (Map.Entry<String, String> e : original.entrySet()) {
            final String key = e.getKey();
            final String value = e.getValue();
            try {
                props.put(key, InterpolationHelper.substVars(value, key, null, props, new InterpolationHelper.SubstitutionCallback() {

                    public String getValue(String toSubstitute) {
                        if (toSubstitute != null && toSubstitute.contains(":")) {
                            String scheme = toSubstitute.substring(0, toSubstitute.indexOf(":"));
                            return resolversSnapshot.get(scheme).resolve(fabricService, mutableConfigurations, pid, key, toSubstitute);
                        }
                        return substituteBundleProperty(toSubstitute, bundleContext);
                    }
                }));
            } catch (EncryptionOperationNotPossibleException exception) {
                LOGGER.warn("Error resolving " + key, exception);
            }
        }
    }
    return mutableConfigurations;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FabricException(io.fabric8.api.FabricException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) FabricService(io.fabric8.api.FabricService) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) PlaceholderResolver(io.fabric8.api.PlaceholderResolver)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7