Search in sources :

Example 16 with ProfileBuilder

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

the class AbstractProfileManagementTest method testCreateUpdateDeleteProfile.

@Test
public void testCreateUpdateDeleteProfile() throws Exception {
    ProfileBuilder pbA10 = ProfileBuilder.Factory.create("1.0", "prfA");
    pbA10.addConfiguration("pidA", Collections.singletonMap("keyA", "valA"));
    ProfileState prfA = getProxy().createProfile(new ProfileState(pbA10.getProfile()));
    try {
        Assert.assertEquals("prfA", prfA.getId());
        Assert.assertEquals("1.0", prfA.getVersion());
        Assert.assertTrue(prfA.getAttributes().isEmpty());
        Assert.assertEquals("valA", prfA.getConfiguration("pidA").get("keyA"));
        // getProfile
        Assert.assertEquals(prfA.toString(), getProxy().getProfile("1.0", "prfA").toString());
        // updateProfile
        prfA = getProxy().getProfile("1.0", "prfA");
        pbA10 = ProfileBuilder.Factory.createFrom(prfA.toProfile());
        pbA10.addConfiguration("pidB", "keyB", "valB");
        prfA = getProxy().updateProfile(new ProfileState(pbA10.getProfile()));
        Assert.assertEquals("prfA", prfA.getId());
        Assert.assertEquals("1.0", prfA.getVersion());
        Assert.assertTrue(prfA.getAttributes().isEmpty());
        Assert.assertEquals("valA", prfA.getConfiguration("pidA").get("keyA"));
        Assert.assertEquals("valB", prfA.getConfiguration("pidB").get("keyB"));
    } finally {
        getProxy().deleteProfile("1.0", "prfA", false);
    }
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder) ProfileState(io.fabric8.api.mxbean.ProfileState) Test(org.junit.Test)

Example 17 with ProfileBuilder

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

the class ProfileCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(profileId);
    } 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 (versionId != null) {
        profileService.getRequiredVersion(versionId);
    } else {
        versionId = fabricService.getDefaultVersionId();
    }
    // we can only use existing parent profiles
    Profile[] parents = FabricCommand.getExistingProfiles(fabricService, versionId, this.parents);
    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
    for (Profile parent : parents) {
        builder.addParent(parent.getId());
    }
    profileService.createProfile(builder.getProfile());
    return null;
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 18 with ProfileBuilder

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

the class ProfileEditAction method editProfile.

private void editProfile(Profile profile) throws Exception {
    boolean editInLine = false;
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    if (delete || remove) {
        editInLine = true;
    }
    if (features != null && features.length > 0) {
        editInLine = true;
        handleFeatures(builder, features, profile);
    }
    if (repositories != null && repositories.length > 0) {
        editInLine = true;
        handleFeatureRepositories(builder, repositories, profile);
    }
    if (libs != null && libs.length > 0) {
        editInLine = true;
        handleLibraries(builder, libs, profile, "lib", LIB_PREFIX);
    }
    if (endorsed != null && endorsed.length > 0) {
        editInLine = true;
        handleLibraries(builder, endorsed, profile, "endorsed lib", ENDORSED_PREFIX);
    }
    if (extension != null && extension.length > 0) {
        editInLine = true;
        handleLibraries(builder, extension, profile, "extension lib", EXT_PREFIX);
    }
    if (bundles != null && bundles.length > 0) {
        editInLine = true;
        handleBundles(builder, bundles, profile);
    }
    if (fabs != null && fabs.length > 0) {
        editInLine = true;
        handleFabs(builder, fabs, profile);
    }
    if (overrides != null && overrides.length > 0) {
        editInLine = true;
        handleOverrides(builder, overrides, profile);
    }
    if (pidProperties != null && pidProperties.length > 0) {
        editInLine = handlePid(builder, pidProperties, profile);
    }
    if (systemProperties != null && systemProperties.length > 0) {
        editInLine = true;
        handleSystemProperties(builder, systemProperties, profile);
    }
    if (configProperties != null && configProperties.length > 0) {
        editInLine = true;
        handleConfigProperties(builder, configProperties, profile);
    }
    if (resource != null && delete) {
        editInLine = true;
        builder.deleteFileConfiguration(resource);
    }
    profileService.updateProfile(builder.getProfile());
    if (!editInLine) {
        resource = resource != null ? resource : "io.fabric8.agent.properties";
        // then open the resource in the editor.
        if (pidProperties != null && pidProperties.length == 1) {
            resource = pidProperties[0] + ".properties";
        }
        openInEditor(profile, resource);
    }
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder)

Example 19 with ProfileBuilder

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

the class GitDataStoreImplProfilesIT method readVersionAndRefreshProfile.

@Test
public void readVersionAndRefreshProfile() {
    gdsi.importFromFileSystem("src/test/resources/distros/distro1/fabric/import");
    Version version = profileRegistry.getVersion("1.0");
    assertNotNull(version);
    Profile defaultProfile = version.getProfile("default");
    assertNotNull(defaultProfile);
    assertThat(defaultProfile.getBundles().size(), equalTo(1));
    assertThat(defaultProfile.getBundles().get(0), equalTo("mvn:io.fabric8/fabric-amazing/${version:fabric}"));
    assertThat(defaultProfile.getFeatures().size(), equalTo(1));
    assertThat(defaultProfile.getFeatures().get(0), equalTo("extraordinary"));
    assertThat(defaultProfile.getConfigurations().size(), equalTo(2));
    assertThat(defaultProfile.getConfigurations().get("my.special.pid").get("property2"), equalTo("value2"));
    assertThat(defaultProfile.getConfigurations().get("io.fabric8.agent").get("some.other.property"), equalTo("valueX"));
    assertThat(defaultProfile.getConfigurations().get("io.fabric8.agent").get("io.fabric8.number.of.sources"), equalTo("42,142,200"));
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(defaultProfile);
    Map<String, String> agentConfiguration = builder.getConfiguration(Constants.AGENT_PID);
    // refresh
    agentConfiguration.put("lastRefresh." + defaultProfile.getId(), String.valueOf(System.currentTimeMillis()));
    agentConfiguration.put("io.fabric8.number.of.sources", "100");
    builder.addConfiguration(Constants.AGENT_PID, agentConfiguration);
    profileRegistry.updateProfile(builder.getProfile());
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with ProfileBuilder

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

the class FabricFeaturesServiceImpl method getVersionProfile.

private Profile getVersionProfile(Version version) {
    String profileId = "#version-" + version.getId();
    ProfileBuilder builder = ProfileBuilder.Factory.create(profileId).version(version.getId());
    VersionProfileOptionsProvider optionsProvider = new VersionProfileOptionsProvider(version);
    return builder.addOptions(optionsProvider).getProfile();
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder)

Aggregations

ProfileBuilder (io.fabric8.api.ProfileBuilder)35 Profile (io.fabric8.api.Profile)33 Version (io.fabric8.api.Version)12 ProfileService (io.fabric8.api.ProfileService)4 GitVersion (io.fabric8.api.commands.GitVersion)3 Test (org.junit.Test)3 VersionBuilder (io.fabric8.api.VersionBuilder)2 ProjectRequirements (io.fabric8.deployer.dto.ProjectRequirements)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Feature (io.fabric8.agent.model.Feature)1 FabricException (io.fabric8.api.FabricException)1 FabricRequirements (io.fabric8.api.FabricRequirements)1 FabricService (io.fabric8.api.FabricService)1 LockHandle (io.fabric8.api.LockHandle)1 ProfileRegistry (io.fabric8.api.ProfileRegistry)1 ProfileRequirements (io.fabric8.api.ProfileRequirements)1 ProfileState (io.fabric8.api.mxbean.ProfileState)1