use of io.fabric8.patch.management.ProfileUpdateStrategy in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method installProfiles.
@Override
public void installProfiles(File gitRepository, String versionId, Patch patch, ProfileUpdateStrategy strategy) {
// remember - we operate on totally different git repository!
// we should have version branch already checked out.
// here we don't merge/cherry-pick anything - we're preparing new commit simply by copying
// one set of profiles (from R patch) over another (current profile definitions from Fabric)
// we won't have merge conflicts, but we can't simply copy profiles over, because existing profiles
// may have custom changes
Git git = null;
try {
git = Git.open(gitRepository);
File src = new File(patch.getPatchData().getPatchDirectory(), "fabric/import/fabric/profiles");
File dst = new File(git.getRepository().getWorkTree(), "fabric/profiles");
// ENTESB-6003:
// let's clean the target directory first, so we can detect file removals in patches (like moving
// jmx.* and org.apache.karaf.command.* PIDs from jboss-fuse-full to acls profile)
FileUtils.deleteDirectory(dst);
dst.mkdir();
ProfileFileUtils.copyDirectory(src, dst, strategy);
git.add().addFilepattern(".").call();
// remove the deletes
for (String missing : git.status().call().getMissing()) {
git.rm().addFilepattern(missing).call();
}
// commit profile changes in patch branch - ultimate commit will be the merge commit
git.commit().setMessage("Installing profiles from patch \"" + patch.getPatchData().getId() + "\"").call();
PatchResult result = patch.getResult();
if (result == null) {
result = new PatchResult(patch.getPatchData(), false, new Date().getTime(), null, null);
patch.setResult(result);
}
result.getVersions().add(versionId);
result.store();
} catch (Exception e) {
throw new PatchException(e.getMessage(), e);
} finally {
if (git != null) {
gitPatchRepository.closeRepository(git, false);
}
}
}
use of io.fabric8.patch.management.ProfileUpdateStrategy in project fabric8 by jboss-fuse.
the class FabricPatchServiceImpl method install.
@Override
public PatchResult install(final Patch patch, boolean simulation, final String versionId, boolean upload, final String username, final String password, final ProfileUpdateStrategy strategy) throws IOException {
// we start from the same state as in standalone mode - after successful patch:add
// we have other things to do in fabric env however:
// 1. check prerequisites
// 2. we don't care about current state of framework - it'll be managed by fabric-agent and we don't
// necessary install a patch for this container we're in
// 3. we don't do patchManagement.beginInstallation / patchManagement.commitInstallation here
// this will be done later - after updated fabric-agent is started
// 4. we don't have to analyze bundles/features/repositories updates - these will be handled simply by
// updating profiles in specified version
PatchKind kind = patch.getPatchData().isRollupPatch() ? PatchKind.ROLLUP : PatchKind.NON_ROLLUP;
if (kind == PatchKind.NON_ROLLUP) {
throw new UnsupportedOperationException("patch:fabric-install should be used for Rollup patches only");
}
String currentContainersVersionId = fabricService.getCurrentContainer().getVersionId();
if (!simulation && versionId.equals(currentContainersVersionId)) {
throw new UnsupportedOperationException("Can't install Rollup patch in current version. Please install" + " this patch in new version and then upgrade existing container(s)");
}
fabricService.adapt(ProfileService.class).getRequiredVersion(versionId);
// just a list of new bundle locations - in fabric the updatable version depends on the moment we
// apply the new version to existing containers.
List<BundleUpdate> bundleUpdatesInThisPatch = bundleUpdatesInPatch(patch);
Presentation.displayBundleUpdates(bundleUpdatesInThisPatch, true);
PatchResult result = new PatchResult(patch.getPatchData(), simulation, System.currentTimeMillis(), bundleUpdatesInThisPatch, null);
if (!simulation) {
// update profile definitions stored in Git. We don't update ${karaf.home}/fabric, becuase it is used
// only once - when importing profiles during fabric:create.
// when fabric is already available, we have to update (Git) repository information
GitOperation operation = new GitOperation() {
@Override
public Object call(Git git, GitContext context) throws Exception {
// we can't pass git reference to patch-management
// because patch-management private-packages git library
// but we can leverage the write lock we have
GitHelpers.checkoutBranch(git, versionId);
// let's get back in history to the point before user changes (profile-edits), but not earlier
// than last R patch
String patchBranch = patchManagement.findLatestPatchRevision(git.getRepository().getDirectory(), versionId);
// now install profiles from patch just like there were no user changes
patchManagement.installProfiles(git.getRepository().getDirectory(), versionId, patch, strategy);
// and finally we have to merge user and patch changes to profiles.
patchManagement.mergeProfileChanges(patch, git.getRepository().getDirectory(), versionId, patchBranch);
context.commitMessage("Installing rollup patch \"" + patch.getPatchData().getId() + "\"");
return null;
}
};
gitDataStore.gitOperation(new GitContext().requireCommit().setRequirePush(true), operation, null);
if (upload) {
PatchManagement.UploadCallback callback = new PatchManagement.UploadCallback() {
@Override
public void doWithUrlConnection(URLConnection connection) throws ProtocolException {
if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection).setRequestMethod("PUT");
}
if (username != null && password != null) {
connection.setRequestProperty("Authorization", "Basic " + Base64Encoder.encode(username + ":" + password));
}
}
};
patchManagement.uploadPatchArtifacts(patch.getPatchData(), fabricService.getMavenRepoUploadURI(), callback);
}
}
return result;
}
use of io.fabric8.patch.management.ProfileUpdateStrategy in project fabric8 by jboss-fuse.
the class FabricInstallAction method doExecute.
@Override
protected void doExecute(Service service) throws Exception {
Patch patch = service.getPatch(patchId);
if (patch == null) {
throw new PatchException("Patch '" + patchId + "' not found");
}
ProfileUpdateStrategy strategy = ProfileUpdateStrategy.GIT;
if ((mergeOverwrite && (mergeSelectNew || mergeKeepExisting)) || (mergeSelectNew && (mergeOverwrite || mergeKeepExisting)) || (mergeKeepExisting && (mergeOverwrite || mergeSelectNew))) {
throw new UnsupportedOperationException("Please select single merge strategy");
}
if (mergeKeepExisting) {
strategy = ProfileUpdateStrategy.PROPERTIES_PREFER_EXISTING;
} else if (mergeSelectNew) {
strategy = ProfileUpdateStrategy.PROPERTIES_PREFER_NEW;
}
PatchResult result = fabricPatchService.install(patch, simulation, versionId, upload, username, password, strategy);
}
Aggregations