use of io.fabric8.api.GitContext 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.api.GitContext in project fabric8 by jboss-fuse.
the class FabricPatchServiceImpl method synchronize.
@Override
public String synchronize(final boolean verbose) throws Exception {
final String[] remoteUrl = new String[] { null };
patchManagement.pushPatchInfo(verbose);
GitOperation operation = new GitOperation() {
@Override
public Object call(Git git, GitContext context) throws Exception {
ProfileRegistry registry = fabricService.adapt(ProfileRegistry.class);
Map<String, String> properties = registry.getDataStoreProperties();
String username;
String password;
if (properties != null && properties.containsKey("gitRemoteUser") && properties.containsKey("gitRemotePassword")) {
username = properties.get("gitRemoteUser");
password = properties.get("gitRemotePassword");
} else {
username = ZooKeeperUtils.getContainerLogin(runtimeProperties);
password = ZooKeeperUtils.generateContainerToken(runtimeProperties, curator);
}
remoteUrl[0] = git.getRepository().getConfig().getString("remote", "origin", "url");
Iterable<PushResult> results = git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)).setPushTags().setPushAll().call();
logPushResult(results, git.getRepository(), verbose);
return null;
}
};
try {
gitDataStore.gitOperation(new GitContext(), operation, null);
} catch (FabricException e) {
if (e.getCause() != null && e.getCause() instanceof TransportException) {
LOG.warn("Problem when synchronizing patch information: " + e.getCause().getMessage());
} else {
throw e;
}
}
return remoteUrl[0];
}
Aggregations