use of io.fabric8.knative.serving.v1.Service 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.knative.serving.v1.Service 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.knative.serving.v1.Service in project fabric8 by jboss-fuse.
the class DetectingGatewayTest method startBrokers.
@Before
public void startBrokers() {
for (int i = 0; i < 2; i++) {
// create a broker..
String name = "broker" + i;
Broker broker = createBroker(name);
ServiceControl.start(broker);
brokers.add(broker);
// Add a service map entry for the broker.
ServiceDTO details = new ServiceDTO();
details.setId(name);
details.setVersion("1.0");
details.setContainer("testing");
details.setBundleName("none");
details.setBundleVersion("1.0");
List<String> services = Arrays.asList("stomp://localhost:" + portOfBroker(i), "mqtt://localhost:" + portOfBroker(i), "amqp://localhost:" + portOfBroker(i), "tcp://localhost:" + portOfBroker(i));
details.setServices(services);
serviceMap.serviceUpdated(name, details);
println(String.format("Broker %s is exposing: %s", name, services));
}
}
use of io.fabric8.knative.serving.v1.Service 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.knative.serving.v1.Service 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