Search in sources :

Example 6 with FabricException

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

the class FabricServiceImpl method validateProfileDependencies.

protected void validateProfileDependencies(CreateContainerOptions options) {
    Map<String, Map<String, String>> profileDependencies = Profiles.getOverlayFactoryConfigurations(this, options.getProfiles(), options.getVersion(), ProfileDependencyConfig.PROFILE_DEPENDENCY_CONFIG_PID);
    Set<Map.Entry<String, Map<String, String>>> entries = profileDependencies.entrySet();
    for (Map.Entry<String, Map<String, String>> entry : entries) {
        String configName = entry.getKey();
        Map<String, String> exportConfig = entry.getValue();
        if (exportConfig != null && !exportConfig.isEmpty()) {
            ProfileDependencyConfig config = new ProfileDependencyConfig();
            try {
                configurer.configure(exportConfig, config);
            } catch (Exception e) {
                throw new FabricException("Failed to load configuration for " + configName + " of " + config + " due to: " + e, e);
            }
            // Ensure dependent container exists
            if (ProfileDependencyKind.ZOOKEEPER_SERVICE.equals(config.getKind())) {
                try {
                    List<String> children = getChildren(this.curator.get(), config.getZookeeperPath());
                    if (children == null || children.isEmpty()) {
                        throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary());
                    }
                    boolean dependencyFound = false;
                    Iterator<String> childIterator = children.iterator();
                    while (!dependencyFound && childIterator.hasNext()) {
                        String containerName = childIterator.next();
                        Container container = this.getContainer(containerName);
                        Profile[] profiles = container.getProfiles();
                        int profileCount = 0;
                        while (!dependencyFound && profileCount < profiles.length) {
                            Profile profile = profiles[profileCount];
                            if (config.getProfileWildcards() != null) {
                                for (String profileWildcard : config.getProfileWildcards()) {
                                    if (profile.getId().contains(profileWildcard)) {
                                        dependencyFound = true;
                                        break;
                                    }
                                }
                            }
                            if (!dependencyFound && config.getProfileTags() != null) {
                                List<String> profileTags = profile.getTags();
                                int foundTags = 0;
                                for (String configProfileTag : config.getProfileTags()) {
                                    if (profileTags.contains(configProfileTag)) {
                                        foundTags++;
                                    }
                                }
                                if (foundTags == config.getProfileTags().length) {
                                    dependencyFound = true;
                                }
                            }
                        }
                    }
                    if (!dependencyFound) {
                        throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary());
                    }
                } catch (Exception e) {
                    throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary(), e);
                }
            }
        }
    }
}
Also used : ProfileDependencyException(io.fabric8.api.ProfileDependencyException) FabricException(io.fabric8.api.FabricException) ProfileDependencyException(io.fabric8.api.ProfileDependencyException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException) Profile(io.fabric8.api.Profile) Entry(java.util.Map.Entry) Container(io.fabric8.api.Container) ProfileDependencyConfig(io.fabric8.internal.ProfileDependencyConfig) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 7 with FabricException

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

the class FabricServiceImpl method getContainer.

@Override
public Container getContainer(String name) {
    assertValid();
    if (dataStore.get().hasContainer(name)) {
        Container parent = null;
        String parentId = dataStore.get().getContainerParent(name);
        if (parentId != null && !parentId.isEmpty()) {
            parent = getContainer(parentId);
        }
        return new ContainerImpl(parent, name, this);
    }
    throw new FabricException("Container '" + name + "' does not exist");
}
Also used : Container(io.fabric8.api.Container) ContainerImpl(io.fabric8.internal.ContainerImpl) FabricException(io.fabric8.api.FabricException)

Example 8 with FabricException

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

the class ProfileServiceImpl method deleteProfile.

@Override
public void deleteProfile(FabricService fabricService, String versionId, String profileId, boolean force) {
    assertValid();
    Profile profile = getRequiredProfile(versionId, profileId);
    LOGGER.info("deleteProfile: {}", profile);
    // TODO: what about child profiles ?
    Container[] containers = fabricService != null ? fabricService.getAssociatedContainers(versionId, profileId) : new Container[0];
    if (containers.length == 0) {
        profileRegistry.get().deleteProfile(versionId, profileId);
    } else if (force) {
        for (Container container : containers) {
            container.removeProfiles(profileId);
        }
        profileRegistry.get().deleteProfile(versionId, profileId);
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append("Cannot delete profile:").append(profileId).append(".");
        sb.append("Profile has assigned ").append(containers.length).append(" container(s):");
        for (Container c : containers) {
            sb.append(" ").append(c.getId());
        }
        sb.append(". Use force option to also remove the profile from the containers.");
        throw new FabricException(sb.toString());
    }
    // lets remove any pending requirements on this profile
    FabricRequirements requirements = fabricService != null ? fabricService.getRequirements() : null;
    if (requirements != null && requirements.removeProfileRequirements(profileId)) {
        try {
            fabricService.setRequirements(requirements);
        } catch (IOException e) {
            throw new FabricException("Failed to update requirements after deleting profile " + profileId + ". " + e, e);
        }
    }
}
Also used : Container(io.fabric8.api.Container) FabricException(io.fabric8.api.FabricException) FabricRequirements(io.fabric8.api.FabricRequirements) IOException(java.io.IOException) Profile(io.fabric8.api.Profile)

Example 9 with FabricException

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

the class BeanUtils method addProperty.

private static void addProperty(Object obj, String field, Map<String, Object> map) {
    try {
        Object prop = PropertyUtils.getProperty(obj, field);
        map.put(field, prop);
    } catch (Exception e) {
        throw new FabricException("Failed to initialize DTO", e);
    }
}
Also used : FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException)

Example 10 with FabricException

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

the class BeanUtils method getFields.

public static List<String> getFields(Class clazz) {
    List<String> answer = new ArrayList<String>();
    try {
        for (PropertyDescriptor desc : PropertyUtils.getPropertyDescriptors(clazz)) {
            if (desc.getReadMethod() != null) {
                answer.add(desc.getName());
            }
        }
    } catch (Exception e) {
        throw new FabricException("Failed to get property descriptors for " + clazz.toString(), e);
    }
    // few tweaks to maintain compatibility with existing views for now...
    if (clazz.getSimpleName().equals("Container")) {
        answer.add("parentId");
        answer.add("versionId");
        answer.add("profileIds");
        answer.add("childrenIds");
        answer.remove("fabricService");
    } else if (clazz.getSimpleName().equals("Profile")) {
        answer.add("id");
        answer.add("parentIds");
        answer.add("childIds");
        answer.add("containerCount");
        answer.add("containers");
        answer.add("fileConfigurations");
    } else if (clazz.getSimpleName().equals("Version")) {
        answer.add("id");
        answer.add("defaultVersion");
    }
    return answer;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException)

Aggregations

FabricException (io.fabric8.api.FabricException)29 IOException (java.io.IOException)10 Container (io.fabric8.api.Container)7 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)6 Lease (org.apache.curator.framework.recipes.locks.Lease)6 HashSet (java.util.HashSet)5 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)5 Session (com.jcraft.jsch.Session)4 FabricService (io.fabric8.api.FabricService)3 Profile (io.fabric8.api.Profile)3 ProfileDependencyException (io.fabric8.api.ProfileDependencyException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ContainerProvider (io.fabric8.api.ContainerProvider)2 ProfileBuilder (io.fabric8.api.ProfileBuilder)2