use of io.fabric8.patch.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.patch.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);
}
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class SimulateAction 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");
}
if (patch.isInstalled()) {
throw new PatchException("Patch '" + patchId + "' is already installed");
}
PatchResult result = service.install(patch, true);
// display(result);
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class FabricTestSupport method destroyChildContainer.
private void destroyChildContainer(FabricService fabricService, CuratorFramework curator, String name) throws InterruptedException {
try {
// Wait for zookeeper service to become available.
Thread.sleep(DEFAULT_WAIT);
// We need this because getContainer will create a container object if container doesn't exists.
if (ZooKeeperUtils.exists(curator, ZkPath.CONTAINER.getPath(name)) != null) {
Container container = fabricService.getContainer(name);
// We want to go through container destroy method so that cleanup methods are properly invoked.
container.destroy();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class ShowAction method doExecute.
@Override
protected void doExecute(Service service) throws Exception {
Patch patch = patchManagement.loadPatch(new PatchDetailsRequest(patchId, bundles, files, diff));
if (patch == null) {
throw new PatchException("Patch '" + patchId + "' not found");
}
System.out.println(String.format("Patch ID: %s", patch.getPatchData().getId()));
if (patch.getManagedPatch() != null) {
System.out.println(String.format("Patch Commit ID: %s", patch.getManagedPatch().getCommitId()));
}
if (bundles) {
System.out.println(String.format("#### %d Bundles%s", patch.getPatchData().getBundles().size(), patch.getPatchData().getBundles().size() == 0 ? "" : ":"));
iterate(patch.getPatchData().getBundles());
}
if (files) {
ManagedPatch details = patch.getManagedPatch();
System.out.println(String.format("#### %d Files added%s", details.getFilesAdded().size(), details.getFilesAdded().size() == 0 ? "" : ":"));
iterate(details.getFilesAdded());
System.out.println(String.format("#### %d Files modified%s", details.getFilesModified().size(), details.getFilesModified().size() == 0 ? "" : ":"));
iterate(details.getFilesModified());
System.out.println(String.format("#### %d Files removed%s", details.getFilesRemoved().size(), details.getFilesRemoved().size() == 0 ? "" : ":"));
iterate(details.getFilesRemoved());
}
if (diff) {
System.out.println("#### Patch changes:\n" + patch.getManagedPatch().getUnifiedDiff());
}
}
Aggregations