Search in sources :

Example 26 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message 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 27 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.

the class FabricGitSummaryAction method printVersions.

private void printVersions(String title, List<GitVersion> versions) {
    System.out.println(title);
    TablePrinter table = new TablePrinter();
    table.columns("version", "SHA1", "timestamp", "message");
    for (GitVersion version : versions) {
        table.row(version.getVersion(), version.getSha1(), version.getTimestamp(), version.getMessage());
    }
    table.print();
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) TablePrinter(io.fabric8.utils.TablePrinter)

Example 28 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method createOrUpdateProfile.

private String createOrUpdateProfile(GitContext context, Profile lastProfile, Profile profile, Set<String> profiles) throws IOException, GitAPIException {
    assertWriteLock();
    String versionId = profile.getVersion();
    String profileId = profile.getId();
    if (!profiles.contains(profileId)) {
        // Process parents first
        for (String parentId : profile.getParentIds()) {
            // skip if parent has been already visited
            if (!profiles.contains(parentId)) {
                Profile parent = getProfileFromCache(profile.getVersion(), parentId);
                IllegalStateAssertion.assertNotNull(parent, "Parent profile does not exist: " + parentId);
            }
        }
        if (lastProfile == null) {
            LOGGER.debug("Create {}", Profiles.getProfileInfo(profile));
        } else {
            LOGGER.debug("Update {}", profile);
            LOGGER.debug("Update {}", Profiles.getProfileDifference(lastProfile, profile));
        }
        // Create the profile branch & directory
        if (lastProfile == null) {
            createProfileDirectoryAfterCheckout(context, versionId, profileId);
        }
        // FileConfigurations
        Map<String, byte[]> fileConfigurations = profile.getFileConfigurations();
        setFileConfigurations(context, versionId, profileId, fileConfigurations);
        // A warning commit message if there has been none yet
        if (context.getCommitMessage().length() == 0) {
            context.commitMessage("WARNING - Profile with no content: " + versionId + "/" + profileId);
        }
        // Mark this profile as processed
        profiles.add(profileId);
    }
    return profileId;
}
Also used : Profile(io.fabric8.api.Profile)

Example 29 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.

the class CachingGitDataStoreTest method testDataStore.

@Test
public void testDataStore() throws Exception {
    // dataStore.getDefaultVersion();
    String defaultVersion = null;
    assertEquals("defaultVersion", "1.0", defaultVersion);
    // now lets import some data - using the old non-git file layout...
    String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric";
    if (useOldImportFormat) {
        assertFolderExists(importPath);
        try {
            dataStore.importFromFileSystem(importPath);
        } catch (Exception e) {
        // Ignore exception about missing url handlers. Not needed for this test anyway.
        }
        assertHasVersion(defaultVersion);
    } else {
        String prefix = importPath + "/fabric";
        String profileImport = prefix + "/configs/versions/1.0/profiles";
        assertFolderExists(profileImport);
        // dataStore.importFromFileSystem(new File(profileImport), "fabric",
        // "1.0", true);
        assertHasVersion(defaultVersion);
    }
    remote.checkout().setName("1.0").call();
    String importedProfile = "example-dozer";
    String profile = importedProfile;
    assertProfileExists(defaultVersion, profile);
    // assertFolderExists("Should have imported an mq/ReadMe.md file!",
    // getLocalGitFile("fabric/profiles/mq/ReadMe.md"));
    String version = "1.1";
    assertCreateVersion("1.0", version);
    assertProfileConfiguration(version, importedProfile, Constants.AGENT_PID, "attribute.parents", "feature-camel");
    assertProfileTextFileConfigurationContains(version, "example-camel-mq", "camel.xml", "http://camel.apache.org/schema/blueprint");
    /*
         * List<String> fileNames = dataStore.getConfigurationFileNames(version,
         * "example-camel-mq"); assertNotNull("Should have some file names",
         * fileNames); assertTrue("Should have some file names",
         * fileNames.size() > 0); assertTrue("Should contain 'came",
         * fileNames.size() > 0);
         * assertCollectionContains("configurationFileNames", fileNames,
         * "camel.xml");
         */
    // lets test the profile attributes
    // dataStore.getProfileAttributes(version, importedProfile);
    Map<String, String> profileAttributes = Collections.emptyMap();
    String parent = profileAttributes.get("parents");
    assertEquals(importedProfile + ".profileAttributes[parent]", "feature-camel", parent);
    System.out.println("Profile attributes: " + profileAttributes);
    String profileAttributeKey = "myKey";
    String expectedProfileAttributeValue = "myValue";
    // dataStore.setProfileAttribute(version, importedProfile, profileAttributeKey, expectedProfileAttributeValue);
    // profileAttributes = dataStore.getProfileAttributes(version, importedProfile);
    System.out.println("Profile attributes: " + profileAttributes);
    assertMapContains("Profile attribute[" + profileAttributeKey + "]", profileAttributes, profileAttributeKey, expectedProfileAttributeValue);
    String hawtioRepoKey = "repository.hawtio";
    // dataStore.getConfiguration(version, "hawtio", Constants.AGENT_PID);
    Map<String, String> hawtioAttrbutes = Collections.emptyMap();
    String currentHawtRepo = hawtioAttrbutes.get(hawtioRepoKey);
    System.out.println("Current repository.hawtio: " + currentHawtRepo);
    // now lets write via the hawtio API
    FabricGitFacade hawtio = new FabricGitFacade();
    hawtio.bindGitDataStoreForTesting(dataStore);
    hawtio.activateForTesting();
    /* String hawtioPropertyFile = "/fabric/profiles/" + dataStore.convertProfileIdToDirectory("hawtio") + "/" + Constants.AGENT_PID + ".properties";
        hawtio.write(version, hawtioPropertyFile, "My commit message", "me", "me@apache.org", "# new file\n" + hawtioRepoKey + " = "
                + "mvn\\:io.hawt/hawtio-karaf/myNewVersion/xml/features" + "\n");
        */
    // dataStore.getConfiguration(version, "hawtio", Constants.AGENT_PID);
    hawtioAttrbutes = Collections.emptyMap();
    String actual = hawtioAttrbutes.get(hawtioRepoKey);
    assertEquals("should have found the updated hawtio repo key", "mvn:io.hawt/hawtio-karaf/myNewVersion/xml/features", actual);
    // lets check that the file configurations recurses into folders
    // Map<String, byte[]> tomcatFileConfigurations = dataStore.getFileConfigurations("1.0", "controller-tomcat");
    // assertHasFileConfiguration(tomcatFileConfigurations, "tomcat/conf/server.xml.mvel");
    /* 
        Collection<String> schemas = dataStore.listFiles("1.0", Arrays.asList("example-dozer"), "schemas");
        assertNotNull(schemas);
        assertContainerEquals("schemas for example-dozer", Arrays.asList("invoice.xsd"), new ArrayList<String>(schemas));
         */
    // check we don't accidentally create a profile
    String profileNotCreated = "shouldNotBeCreated";
    // assertEquals("Should not create profile: " + profileNotCreated, null, dataStore.getProfile(version, profileNotCreated, false));
    assertProfileNotExists(defaultVersion, profileNotCreated);
    // assertFolderNotExists(getLocalGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profileNotCreated)));
    // now lets create some profiles in this new version
    String newProfile = "myNewProfile";
    // dataStore.createProfile(version, newProfile);
    assertProfileExists(version, newProfile);
    // lazy create a profile
    String anotherNewProfile = "anotherNewProfile";
    // dataStore.getProfile(version, anotherNewProfile, true);
    assertProfileExists(version, anotherNewProfile);
    version = "1.2";
    assertCreateVersion("1.1", version);
    // check this version has the profile too
    assertProfileExists(version, newProfile);
    assertProfileExists(version, profile);
    // now lets delete a profile
    dataStore.deleteProfile(version, newProfile);
    assertProfileNotExists(version, newProfile);
    // lets check the remote repo
    remote.checkout().setName("1.1").call();
    assertProfileExists("1.1", profile);
    assertProfileExists("1.1", newProfile);
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profile)));
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(newProfile)));
    remote.checkout().setName("1.2").call();
    assertProfileExists("1.2", profile);
    assertProfileNotExists("1.2", newProfile);
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profile)));
    // assertFolderNotExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(newProfile)));
    remote.checkout().setName("1.0").call();
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profile)));
    // assertFolderNotExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(newProfile)));
    // delete version 1.2
    assertHasVersion("1.1");
    assertHasVersion("1.2");
    // dataStore.removeVersion("1.2");
    assertHasVersion("1.1");
    assertHasNotVersion("1.2");
    Collection<String> remoteBranches = RepositoryUtils.getBranches(remote.getRepository());
    System.out.println("Remote branches after delete: " + remoteBranches);
}
Also used : FabricGitFacade(io.fabric8.git.hawtio.FabricGitFacade) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceImpl method trackBaselineRepository.

/**
 * Adds baseline distribution to the repository. It serves a different purpose in fabric and standalone scenarios.
 * In fabric mode, we put another baseline tag for root container when it is upgraded to specific version. The
 * versioning of root container is performed on another branch.
 * In standalone mode mode, the same branch is used to track baselines and for versioning of the container itself.
 * In standalone mode, patches are added to separate branch each.
 * In fabric mode, patches are added to baseline branches and each container has it's own versioning branch
 * (private, not pushed to main repository).
 * @param git non-bare repository to perform the operation with correct branch checked out already
 */
private RevCommit trackBaselineRepository(Git git) throws IOException, GitAPIException {
    // initialize repo with baseline version and push to reference repo
    String currentFuseVersion = determineVersion(karafHome, "fuse");
    String currentFabricVersion = determineVersion(karafHome, "fabric");
    // check what product are we in
    File systemRepo = getSystemRepository(karafHome, systemContext);
    File baselineDistribution = null;
    String baselineLocation = Utils.getBaselineLocationForProduct(karafHome, systemContext, currentFuseVersion);
    if (baselineLocation != null) {
        baselineDistribution = new File(patchesDir, baselineLocation);
    } else {
        // do some guessing - first JBoss Fuse, then JBoss A-MQ
        String[] locations = new String[] { systemRepo.getCanonicalPath() + "/org/jboss/fuse/jboss-fuse-karaf/%1$s/jboss-fuse-karaf-%1$s-baseline.zip", patchesDir.getCanonicalPath() + "/jboss-fuse-karaf-%1$s-baseline.zip", systemRepo.getCanonicalPath() + "/org/jboss/amq/jboss-a-mq/%s/jboss-a-mq-%1$s-baseline.zip", patchesDir.getCanonicalPath() + "/jboss-a-mq-%1$s-baseline.zip" };
        for (String location : locations) {
            location = String.format(location, currentFuseVersion);
            if (new File(location).isFile()) {
                baselineDistribution = new File(location);
                Activator.log(LogService.LOG_INFO, "Found baseline distribution: " + baselineDistribution.getCanonicalPath());
                break;
            }
        }
    }
    if (baselineDistribution != null) {
        return trackBaselineRepository(git, baselineDistribution, currentFuseVersion);
    } else {
        String message = "Can't find baseline distribution in patches dir or inside system repository.";
        Activator.log2(LogService.LOG_WARNING, message);
        throw new PatchException(message);
    }
}
Also used : PatchException(io.fabric8.patch.management.PatchException) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Aggregations

IOException (java.io.IOException)12 HashMap (java.util.HashMap)9 File (java.io.File)8 Profile (io.fabric8.api.Profile)7 Map (java.util.Map)7 Message (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message)6 ArrayList (java.util.ArrayList)5 PatchException (io.fabric8.patch.management.PatchException)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 Container (io.fabric8.api.Container)3 Version (io.fabric8.api.Version)3 Date (java.util.Date)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Git (org.eclipse.jgit.api.Git)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Test (org.junit.Test)3