Search in sources :

Example 21 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class MQCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    MQBrokerConfigDTO dto = createDTO();
    Profile profile = MQManager.createOrUpdateProfile(dto, fabricService, runtimeProperties);
    if (profile == null) {
        return null;
    }
    String profileId = profile.getId();
    System.out.println("MQ profile " + profileId + " ready");
    // assign profile to existing containers
    if (assign != null) {
        String[] assignContainers = assign.split(",");
        MQManager.assignProfileToContainers(fabricService, profile, assignContainers);
    }
    // create containers
    if (create != null) {
        String[] createContainers = create.split(",");
        List<CreateContainerBasicOptions.Builder> builderList = MQManager.createContainerBuilders(dto, fabricService, "child", profileId, dto.version(), createContainers);
        for (CreateContainerBasicOptions.Builder builder : builderList) {
            CreateContainerMetadata[] metadatas;
            try {
                if (builder instanceof CreateChildContainerOptions.Builder) {
                    CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
                    builder = childBuilder.jmxUser(username).jmxPassword(password);
                }
                metadatas = fabricService.createContainers(builder.build());
                // check if there was a FabricAuthenticationException as failure then we can try again
                if (metadatas != null) {
                    for (CreateContainerMetadata meta : metadatas) {
                        if (meta.getFailure() != null && meta.getFailure() instanceof FabricAuthenticationException) {
                            throw (FabricAuthenticationException) meta.getFailure();
                        }
                    }
                }
                ShellUtils.storeFabricCredentials(session, username, password);
            } catch (FabricAuthenticationException fae) {
                // If authentication fails, prompts for credentials and try again.
                if (builder instanceof CreateChildContainerOptions.Builder) {
                    CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
                    promptForJmxCredentialsIfNeeded();
                    metadatas = fabricService.createContainers(childBuilder.jmxUser(username).jmxPassword(password).build());
                    ShellUtils.storeFabricCredentials(session, username, password);
                }
            }
        }
    }
    return null;
}
Also used : FabricAuthenticationException(io.fabric8.api.FabricAuthenticationException) CreateChildContainerOptions(io.fabric8.api.CreateChildContainerOptions) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) Profile(io.fabric8.api.Profile) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions)

Example 22 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class ProfileChangeParentsAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getRequiredProfile(profileId);
    // we can only change parents to existing profiles
    Profile[] parents = FabricCommand.getExistingProfiles(fabricService, version, parentIds);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    List<String> oldParents = builder.getParents();
    for (Profile parent : parents) {
        builder.addParent(parent.getId());
    }
    // remove old parent profiles
    for (String oldParent : oldParents) {
        if (!parentIds.contains(oldParent)) {
            builder.removeParent(oldParent);
        }
    }
    profileService.updateProfile(builder.getProfile());
    return null;
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 23 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class ProfileEditAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(profileName);
        if (!(delete || remove)) {
            FabricValidations.validatePidProperties(pidProperties);
        }
    } 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;
    }
    if (delete) {
        set = false;
    }
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getProfile(profileName);
    if (profile != null) {
        editProfile(profile);
    } else {
        System.out.println("Profile " + profileName + " does not exists!");
        return 1;
    }
    return null;
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 24 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class ProfileScaleAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(name);
    } 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;
    }
    fabricService.scaleProfile(name, count);
    ProfileRequirements profileRequirements = fabricService.getRequirements().getOrCreateProfileRequirement(name);
    Integer minimumInstances = profileRequirements.getMinimumInstances();
    int size = Containers.containersForProfile(fabricService.getContainers(), name).size();
    PrintStream output = System.out;
    output.println("Profile " + name + " " + (minimumInstances != null ? "now requires " + minimumInstances + " container(s)" : "does not require any containers") + " currently has " + size + " container(s) running");
    return null;
}
Also used : PrintStream(java.io.PrintStream) ProfileRequirements(io.fabric8.api.ProfileRequirements)

Example 25 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class RequireProfileListAction method printRequirements.

@Override
protected void printRequirements(PrintStream out, FabricRequirements requirements) {
    TablePrinter table = new TablePrinter();
    table.columns("profile", "# minimum", "# maximum", "depends on");
    List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
    for (ProfileRequirements profile : profileRequirements) {
        table.row(profile.getProfile(), getStringOrBlank(profile.getMinimumInstances()), getStringOrBlank(profile.getMaximumInstances()), getStringOrBlank(profile.getDependentProfiles()));
    }
    table.print();
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) TablePrinter(io.fabric8.utils.TablePrinter)

Aggregations

Profile (io.fabric8.api.Profile)125 Version (io.fabric8.api.Version)50 Container (io.fabric8.api.Container)49 ArrayList (java.util.ArrayList)37 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Test (org.junit.Test)32 FabricService (io.fabric8.api.FabricService)28 HashMap (java.util.HashMap)25 File (java.io.File)24 ProfileService (io.fabric8.api.ProfileService)23 Map (java.util.Map)22 IOException (java.io.IOException)19 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 HashSet (java.util.HashSet)12 GitVersion (io.fabric8.api.commands.GitVersion)11 FabricRequirements (io.fabric8.api.FabricRequirements)10 LinkedList (java.util.LinkedList)9 TreeMap (java.util.TreeMap)9 LockHandle (io.fabric8.api.LockHandle)8 Parser (io.fabric8.maven.util.Parser)8