Search in sources :

Example 26 with FabricException

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

the class OpenshiftContainerProvider method getContainerApplication.

private IApplication getContainerApplication(Container container, boolean required) {
    IApplication app = null;
    CreateOpenshiftContainerMetadata metadata = OpenShiftUtils.getContainerMetadata(container);
    if (metadata != null) {
        IOpenShiftConnection connection = getOrCreateConnection(metadata.getCreateOptions());
        app = OpenShiftUtils.getApplication(container, metadata, connection);
    }
    if (app == null && required) {
        throw new FabricException("Unable to find OpenShift application for " + container.getId());
    }
    return app;
}
Also used : IApplication(com.openshift.client.IApplication) IOpenShiftConnection(com.openshift.client.IOpenShiftConnection) FabricException(io.fabric8.api.FabricException)

Example 27 with FabricException

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

the class ClusterBootstrapManager method getCreateEnsembleOptions.

static CreateEnsembleOptions getCreateEnsembleOptions(RuntimeProperties sysprops, Map<String, Object> options) {
    String username = (String) options.remove("username");
    String password = (String) options.remove("password");
    String role = (String) options.remove("role");
    if (username == null || password == null || role == null) {
        throw new FabricException("Must specify an administrator username, password and administrative role when creating a fabric");
    }
    Object profileObject = options.remove("profiles");
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    CreateEnsembleOptions.Builder builder = mapper.convertValue(options, CreateEnsembleOptions.Builder.class);
    if (profileObject != null) {
        List profiles = mapper.convertValue(profileObject, List.class);
        builder.profiles(profiles);
    }
    org.apache.felix.utils.properties.Properties userProps = null;
    try {
        userProps = new org.apache.felix.utils.properties.Properties(sysprops.getConfPath().resolve("users.properties").toFile());
    } catch (IOException e) {
        userProps = new org.apache.felix.utils.properties.Properties();
    }
    if (userProps.get(username) == null) {
        userProps.put(username, password + "," + role);
    }
    CreateEnsembleOptions answer = builder.users(userProps).withUser(username, password, role).build();
    LOG.debug("Creating ensemble with options: {}", answer);
    System.setProperty(ZkDefs.GLOBAL_RESOLVER_PROPERTY, answer.getGlobalResolver());
    System.setProperty(ZkDefs.LOCAL_RESOLVER_PROPERTY, answer.getResolver());
    System.setProperty(ZkDefs.MANUAL_IP, answer.getManualIp());
    System.setProperty(ZkDefs.BIND_ADDRESS, answer.getBindAddress());
    System.setProperty(ZkDefs.MINIMUM_PORT, "" + answer.getMinimumPort());
    System.setProperty(ZkDefs.MAXIMUM_PORT, "" + answer.getMaximumPort());
    return answer;
}
Also used : FabricException(io.fabric8.api.FabricException) CreateEnsembleOptions(io.fabric8.api.CreateEnsembleOptions) IOException(java.io.IOException) RuntimeProperties(io.fabric8.api.RuntimeProperties) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 28 with FabricException

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

the class FabricManager method applyPatches.

@Override
public void applyPatches(List<String> files, String sourceId, String targetId, String proxyUser, String proxyPassword) {
    List<File> patchFiles = new ArrayList<File>();
    for (String fileName : files) {
        File file = new File(fileName);
        if (file.exists()) {
            patchFiles.add(file);
        } else {
            LOG.warn("Patch file does not exist, skipping: {}", fileName);
        }
    }
    if (patchFiles.isEmpty()) {
        LOG.warn("No valid patches to apply");
        throw new FabricException("No valid patches to apply");
    }
    if (targetId == null || targetId.equals("")) {
        Version latestVersion = getLatestVersion();
        VersionSequence sequence = new VersionSequence(latestVersion.getId());
        targetId = sequence.next().getName();
    }
    Version targetVersion = profileService.createVersionFrom(sourceId, targetId, null);
    File currentPatchFile = null;
    try {
        for (File file : patchFiles) {
            currentPatchFile = file;
            if (!file.isFile()) {
                LOG.info("File is a directory, skipping: {}", file);
                continue;
            }
            LOG.info("Applying patch file {}", file);
            fabricService.getPatchService().applyPatch(targetVersion, file.toURI().toURL(), proxyUser, proxyPassword);
            LOG.info("Successfully applied {}", file);
        }
    } catch (Throwable t) {
        LOG.warn("Failed to apply patch file {}", currentPatchFile, t);
        profileService.deleteVersion(targetId);
        throw new FabricException("Failed to apply patch file " + currentPatchFile, t);
    }
    for (File file : patchFiles) {
        try {
            LOG.info("Deleting patch file {}", file);
            boolean deleted = file.delete();
            if (!deleted) {
                LOG.warn("Failed to delete patch file {}", file);
            }
        } catch (Throwable t) {
            LOG.warn("Failed to delete patch file {} due to {}", file, t);
        }
    }
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList) FabricException(io.fabric8.api.FabricException) File(java.io.File) VersionSequence(io.fabric8.api.VersionSequence)

Example 29 with FabricException

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

the class FabricManager method deleteConfigurationFiles.

@Override
public void deleteConfigurationFiles(String versionId, List<String> profileIds, List<String> fileNames) {
    if (profileIds.size() != fileNames.size()) {
        throw new FabricException("Lists of profile IDs and filenames should be the same size");
    }
    for (int i = 0; i < profileIds.size(); i++) {
        String profileId = profileIds.get(i);
        String fileName = fileNames.get(i);
        Profile profile = profileService.getRequiredProfile(versionId, profileId);
        ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
        builder.deleteFileConfiguration(fileName);
        profileService.updateProfile(builder.getProfile());
    }
}
Also used : FabricException(io.fabric8.api.FabricException) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 30 with FabricException

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

the class CreateContainerTask method call.

@Override
public Set<ContainerProxy> call() throws Exception {
    Set<ContainerProxy> containers = new HashSet<ContainerProxy>();
    FabricService fabricService = fabricServiceProxy.getService();
    CreateContainerMetadata[] allMetadata = fabricService.createContainers(options);
    if (allMetadata != null && allMetadata.length > 0) {
        for (CreateContainerMetadata metadata : allMetadata) {
            Container container = metadata.getContainer();
            containers.add(ContainerProxy.wrap(container, fabricServiceProxy));
            if (!metadata.isSuccess()) {
                throw new FabricException("Failed to create container.", metadata.getFailure());
            }
        }
    }
    return containers;
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) HashSet(java.util.HashSet)

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