Search in sources :

Example 1 with VersionSequence

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

the class VersionCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    String latestVersion = null;
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    List<String> versions = profileService.getVersions();
    if (versions.size() > 0) {
        latestVersion = versions.get(versions.size() - 1);
    }
    if (versionId == null) {
        IllegalStateAssertion.assertNotNull(latestVersion, "Cannot default the new version name as there are no versions available");
        VersionSequence sequence = new VersionSequence(latestVersion);
        versionId = sequence.next().getName();
    }
    // TODO we maybe want to choose the version which is less than the 'name' if it was specified
    // e.g. if you create a version 1.1 then it should use 1.0 if there is already a 2.0
    String sourceId = null;
    if (parentVersion == null) {
        sourceId = latestVersion;
    } else {
        IllegalStateAssertion.assertTrue(profileService.hasVersion(parentVersion), "Cannot find parent version: " + parentVersion);
        sourceId = parentVersion;
    }
    Version targetVersion;
    if (sourceId != null) {
        Map<String, String> attributes = new HashMap<String, String>(Collections.singletonMap(Version.PARENT, sourceId));
        if (description != null) {
            attributes.put(Version.DESCRIPTION, description);
        }
        targetVersion = profileService.createVersionFrom(sourceId, versionId, attributes);
        System.out.println("Created version: " + versionId + " as copy of: " + sourceId);
    } else {
        VersionBuilder builder = VersionBuilder.Factory.create(versionId);
        if (description != null) {
            builder.addAttribute(Version.DESCRIPTION, description);
        }
        targetVersion = profileService.createVersion(builder.getVersion());
        System.out.println("Create version: " + versionId);
    }
    if (defaultVersion == Boolean.TRUE) {
        fabricService.setDefaultVersionId(targetVersion.getId());
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) HashMap(java.util.HashMap) VersionBuilder(io.fabric8.api.VersionBuilder) VersionSequence(io.fabric8.api.VersionSequence)

Example 2 with VersionSequence

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

the class FabricManager method createVersion.

@Override
public Map<String, Object> createVersion() {
    Version latestVersion = getLatestVersion();
    VersionSequence sequence = new VersionSequence(latestVersion.getId());
    return createVersion(sequence.next().getName());
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) VersionSequence(io.fabric8.api.VersionSequence)

Example 3 with VersionSequence

use of io.fabric8.api.VersionSequence 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)

Aggregations

Version (io.fabric8.api.Version)3 VersionSequence (io.fabric8.api.VersionSequence)3 GitVersion (io.fabric8.api.commands.GitVersion)2 FabricException (io.fabric8.api.FabricException)1 ProfileService (io.fabric8.api.ProfileService)1 VersionBuilder (io.fabric8.api.VersionBuilder)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1