use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method installPPatchHotFixPPatchAndThenRPatch.
/**
* Installation of R patch <strong>may</strong> leave P patches installed when they provide <strong>only</strong>
* bundles and the bundles are at higher version
* @throws IOException
* @throws GitAPIException
*/
@Test
public void installPPatchHotFixPPatchAndThenRPatch() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
preparePatchZip("src/test/resources/content/patch2", "target/karaf/patches/source/patch-2.zip", false);
preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
PatchManagement service = (PatchManagement) pm;
PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
Patch patch1 = service.trackPatch(patchData1);
PatchData patchData2 = service.fetchPatches(new File("target/karaf/patches/source/patch-2.zip").toURI().toURL()).get(0);
Patch patch2 = service.trackPatch(patchData2);
PatchData patchData4 = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
Patch patch4 = service.trackPatch(patchData4);
String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch1, null);
service.commitInstallation(tx);
tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch2, null);
service.commitInstallation(tx);
assertTrue("There should be etc/overrides.properties after installing non-rollup patches", new File(karafHome, "etc/overrides.properties").exists());
// overrides.properties as after installing P patches with new mechanism
String etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
assertThat(etcOverridesProperties, equalTo("mvn:io.fabric8/fabric-tranquility/1.2.5\n"));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
assertTrue(repository.containsTag(fork, "patch-my-patch-2"));
assertFalse(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
repository.closeRepository(fork, true);
tx = service.beginInstallation(PatchKind.ROLLUP);
service.install(tx, patch4, null);
service.commitInstallation(tx);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
assertFalse(repository.containsTag(fork, "patch-my-patch-2"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
assertTrue("There still should be etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
// overrides.properties as after installing R patch with new mechanism
etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
assertThat(etcOverridesProperties, equalTo("mvn:io.fabric8/fabric-tranquility/1.2.5\n"));
repository.closeRepository(fork, true);
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method addPatch1.
/**
* Patch 1 is non-rollup patch
* @throws IOException
* @throws GitAPIException
*/
@Test
public void addPatch1() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
PatchManagement service = (PatchManagement) pm;
PatchData patchData = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
assertThat(patchData.getId(), equalTo("my-patch-1"));
Patch patch = service.trackPatch(patchData);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
// we should see remote branch for the patch, but without checking it out, it won't be available in the clone's local branches
List<Ref> branches = fork.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
Ref patchBranch = null;
for (Ref remoteBranch : branches) {
if (String.format("refs/remotes/origin/patch-%s", patchData.getId()).equals(remoteBranch.getName())) {
patchBranch = remoteBranch;
break;
}
}
assertNotNull("Should find remote branch for the added patch", patchBranch);
assertThat(patch.getManagedPatch().getCommitId(), equalTo(patchBranch.getObjectId().getName()));
RevCommit patchCommit = new RevWalk(fork.getRepository()).parseCommit(patchBranch.getObjectId());
// patch commit should be child of baseline commit
RevCommit baselineCommit = new RevWalk(fork.getRepository()).parseCommit(patchCommit.getParent(0));
// this baseline commit should be tagged "baseline-VERSION"
Ref tag = fork.tagList().call().get(0);
assertThat(tag.getName(), equalTo("refs/tags/baseline-6.2.0"));
RevCommit baselineCommitFromTag = new RevWalk(fork.getRepository()).parseCommit(tag.getTarget().getObjectId());
assertThat(baselineCommit.getId(), equalTo(baselineCommitFromTag.getId()));
// let's see the patch applied to baseline-6.2.0
fork.checkout().setName("my-patch-1").setStartPoint("origin/patch-my-patch-1").setCreateBranch(true).call();
String myProperties = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/my.properties"));
assertTrue(myProperties.contains("p1 = v1"));
repository.closeRepository(fork, true);
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method validateInitialGitRepository.
private void validateInitialGitRepository() throws IOException, GitAPIException {
pm = new GitPatchManagementServiceImpl(bundleContext);
pm.start();
pm.ensurePatchManagementInitialized();
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
verify(bsl, atLeastOnce()).setStartLevel(2);
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
List<Ref> tags = fork.tagList().call();
boolean found = false;
for (Ref tag : tags) {
if ("refs/tags/baseline-6.2.0".equals(tag.getName())) {
found = true;
break;
}
}
assertTrue("Repository should contain baseline tag for version 6.2.0", found);
// look in etc/startup.properties for installed patch-management bundle
List<String> lines = FileUtils.readLines(new File(karafHome, "etc/startup.properties"));
found = false;
for (String line : lines) {
if ("io/fabric8/patch/patch-management/1.1.9/patch-management-1.1.9.jar=2".equals(line)) {
fail("Should not contain old patch-management bundle in etc/startup.properties");
}
if ("io/fabric8/patch/patch-management/1.2.0/patch-management-1.2.0.jar=2".equals(line)) {
if (found) {
fail("Should contain only one declaration of patch-management bundle in etc/startup.properties");
}
found = true;
}
}
repository.closeRepository(fork, true);
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class HttpMappingRuleBase method updateMappingRules.
/**
* Given a path being added or removed, update the services.
*
* @param remove whether to remove (if true) or add (if false) this mapping
* @param path the path that this mapping is bound
* @param services the HTTP URLs of the services to map to
* @param defaultParams the default parameters to use in the URI templates such as for version and container
* @param serviceDetails
*/
public void updateMappingRules(boolean remove, String path, List<String> services, Map<String, String> defaultParams, ServiceDetails serviceDetails) {
SimplePathTemplate pathTemplate = getUriTemplate();
if (pathTemplate != null) {
boolean versionSpecificUri = pathTemplate.getParameterNames().contains("version");
String versionId = defaultParams.get("version");
if (!remove && Strings.isNotBlank(versionId) && !versionSpecificUri && gatewayVersion != null) {
// lets ignore this mapping if the version does not match
if (!gatewayVersion.equals(versionId)) {
remove = true;
}
}
Map<String, String> params = new HashMap<String, String>();
if (defaultParams != null) {
params.putAll(defaultParams);
}
params.put("servicePath", path);
if (!versionSpecificUri && Strings.isNotBlank(this.enabledVersion)) {
if (!serviceDetails.getVersion().equals(this.enabledVersion)) {
remove = true;
}
}
for (String service : services) {
populateUrlParams(params, service);
String fullPath = pathTemplate.bindByNameNonStrict(params);
if (remove) {
MappedServices rule = mappingRules.get(fullPath);
if (rule != null) {
List<String> serviceUrls = rule.getServiceUrls();
serviceUrls.remove(service);
if (serviceUrls.isEmpty()) {
mappingRules.remove(fullPath);
}
}
} else {
MappedServices mappedServices = new MappedServices(service, serviceDetails, loadBalancer, reverseHeaders);
MappedServices oldRule = mappingRules.put(fullPath, mappedServices);
if (oldRule != null) {
mappedServices.getServiceUrls().addAll(oldRule.getServiceUrls());
}
}
}
}
fireMappingRulesChanged();
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class HttpMappingZooKeeperTreeCache method treeCacheEvent.
protected void treeCacheEvent(PathChildrenCacheEvent event) {
String zkPath = zooKeeperPath;
ChildData childData = event.getData();
if (childData == null) {
return;
}
String path = childData.getPath();
Type type = event.getType();
byte[] data = childData.getData();
if (data == null || data.length == 0 || path == null) {
return;
}
if (path.startsWith(zkPath)) {
path = path.substring(zkPath.length());
}
// TODO should we remove the version too and pick that one?
// and include the version in the service chooser?
boolean remove = false;
switch(type) {
case CHILD_ADDED:
case CHILD_UPDATED:
break;
case CHILD_REMOVED:
remove = true;
break;
default:
return;
}
ServiceDTO dto = null;
try {
dto = mapper.readValue(data, ServiceDTO.class);
expandPropertyResolvers(dto);
List<String> services = dto.getServices();
Map<String, String> params = new HashMap<String, String>();
params.put("id", paramValue(dto.getId()));
params.put("container", paramValue(dto.getContainer()));
params.put("version", paramValue(dto.getVersion()));
params.put("bundleName", paramValue(dto.getBundleName()));
params.put("bundleVersion", paramValue(dto.getBundleVersion()));
mappingRuleConfiguration.updateMappingRules(remove, path, services, params, dto);
} catch (IOException e) {
LOG.warn("Failed to parse the JSON: " + new String(data) + ". Reason: " + e, e);
} catch (URISyntaxException e) {
LOG.warn("Failed to update URI for dto: " + dto + ", .Reason: " + e, e);
}
}
Aggregations