use of io.fabric8.knative.serving.v1.Service in project fabric8 by jboss-fuse.
the class ServiceImplTest method bundleUpdatesInPatch.
@Test
public void bundleUpdatesInPatch() throws Exception {
BundleContext context = EasyMock.createMock(BundleContext.class);
Bundle bundle0 = createMock(Bundle.class);
expect(bundle0.getBundleContext()).andReturn(context);
replay(bundle0);
expect(context.getProperty("karaf.home")).andReturn("target/bundleUpdatesInPatch").anyTimes();
expect(context.getProperty("karaf.base")).andReturn("target/bundleUpdatesInPatch").anyTimes();
expect(context.getProperty("karaf.data")).andReturn("target/bundleUpdatesInPatch/data").anyTimes();
expect(context.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(context.getProperty("karaf.instances")).andReturn("instances").anyTimes();
expect(context.getProperty("karaf.default.repository")).andReturn("system");
expect(context.getProperty("fuse.patch.location")).andReturn(null);
expect(context.getBundle(0)).andReturn(bundle0);
replay(context);
ServiceImpl service = new ServiceImpl();
Method m = service.getClass().getDeclaredMethod("bundleUpdatesInPatch", Patch.class, Bundle[].class, Map.class, ServiceImpl.BundleVersionHistory.class, Map.class, PatchKind.class, Map.class, List.class);
m.setAccessible(true);
Field f = service.getClass().getDeclaredField("helper");
f.setAccessible(true);
f.set(service, new OSGiPatchHelper(new File("target/bundleUpdatesInPatch"), context) {
@Override
public String[] getBundleIdentity(String url) throws IOException {
Artifact a = Utils.mvnurlToArtifact(url, false);
return new String[] { a.getArtifactId(), a.getVersion() };
}
});
PatchData pd = new PatchData("patch-x");
// for these two, bundle.getLocation() will return matching location
pd.getBundles().add("mvn:io.fabric8/pax-romana/1.0.1");
pd.getBundles().add("mvn:io.fabric8/pax-hellenica/1.0.1/jar");
// for these two, bundle.getLocation() will return non-matching location
pd.getBundles().add("mvn:io.fabric8/pax-bohemia/1.0.1");
pd.getBundles().add("mvn:io.fabric8/pax-pomerania/1.0.1/jar");
// for these two, bundle.getLocation() will return matching location
pd.getBundles().add("mvn:io.fabric8/pax-avaria/1.0.1/jar/uber");
pd.getBundles().add("mvn:io.fabric8/pax-mazovia/1.0.1//uber");
// for these two, bundle.getLocation() will return non-matching location
pd.getBundles().add("mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber");
pd.getBundles().add("mvn:io.fabric8/pax-castile/1.0.1//uber");
f = pd.getClass().getDeclaredField("versionRanges");
f.setAccessible(true);
f.set(pd, new HashMap<>());
Patch patch = new Patch(pd, null);
Bundle[] bundles = new Bundle[8];
bundles[0] = bundle("mvn:io.fabric8/pax-romana/1.0.0");
bundles[1] = bundle("mvn:io.fabric8/pax-hellenica/1.0.0/jar");
bundles[2] = bundle("mvn:io.fabric8/pax-bohemia/1.0.0/jar");
bundles[3] = bundle("mvn:io.fabric8/pax-pomerania/1.0.0");
bundles[4] = bundle("mvn:io.fabric8/pax-avaria/1.0.0/jar/uber");
bundles[5] = bundle("mvn:io.fabric8/pax-mazovia/1.0.0//uber");
bundles[6] = bundle("mvn:io.fabric8/pax-novgorod/1.0.0//uber");
bundles[7] = bundle("mvn:io.fabric8/pax-castile/1.0.0/jar/uber");
Object _list = m.invoke(service, patch, bundles, new HashMap<>(), new ServiceImpl.BundleVersionHistory(new HashMap<String, Patch>()), new HashMap<>(), PatchKind.NON_ROLLUP, new HashMap<>(), null);
List<BundleUpdate> list = (List<BundleUpdate>) _list;
assertThat(list.size(), equalTo(8));
assertThat(list.get(0).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-romana/1.0.0"));
assertThat(list.get(1).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-hellenica/1.0.0/jar"));
assertThat(list.get(2).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-bohemia/1.0.0/jar"));
assertThat(list.get(3).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-pomerania/1.0.0"));
assertThat(list.get(4).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-avaria/1.0.0/jar/uber"));
assertThat(list.get(5).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-mazovia/1.0.0//uber"));
assertThat(list.get(6).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-novgorod/1.0.0//uber"));
assertThat(list.get(7).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-castile/1.0.0/jar/uber"));
assertThat(list.get(0).getNewLocation(), equalTo("mvn:io.fabric8/pax-romana/1.0.1"));
assertThat(list.get(1).getNewLocation(), equalTo("mvn:io.fabric8/pax-hellenica/1.0.1/jar"));
assertThat(list.get(2).getNewLocation(), equalTo("mvn:io.fabric8/pax-bohemia/1.0.1"));
assertThat(list.get(3).getNewLocation(), equalTo("mvn:io.fabric8/pax-pomerania/1.0.1/jar"));
assertThat(list.get(4).getNewLocation(), equalTo("mvn:io.fabric8/pax-avaria/1.0.1/jar/uber"));
assertThat(list.get(5).getNewLocation(), equalTo("mvn:io.fabric8/pax-mazovia/1.0.1//uber"));
assertThat(list.get(6).getNewLocation(), equalTo("mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber"));
assertThat(list.get(7).getNewLocation(), equalTo("mvn:io.fabric8/pax-castile/1.0.1//uber"));
// ---
Repository repository = createMock(Repository.class);
File tmp = new File("target/bundleUpdatesInPatch/" + UUID.randomUUID().toString());
tmp.mkdirs();
File startupProperties = new File(tmp, "etc/startup.properties");
FileUtils.copyFile(new File("src/test/resources/uber-startup.properties"), startupProperties);
expect(repository.getWorkTree()).andReturn(tmp).anyTimes();
replay(repository);
Git fork = createMock(Git.class);
expect(fork.getRepository()).andReturn(repository).anyTimes();
replay(fork);
GitPatchManagementServiceImpl gitPatchManagementService = new GitPatchManagementServiceImpl(context);
m = gitPatchManagementService.getClass().getDeclaredMethod("updateFileReferences", Git.class, PatchData.class, List.class);
m.setAccessible(true);
m.invoke(gitPatchManagementService, fork, pd, list);
try (FileReader reader = new FileReader(startupProperties)) {
Properties startup = new Properties();
startup.load(reader);
assertTrue(startup.containsKey("io/fabric8/pax-romana/1.0.1/pax-romana-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-hellenica/1.0.1/pax-hellenica-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-bohemia/1.0.1/pax-bohemia-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-pomerania/1.0.1/pax-pomerania-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-avaria/1.0.1/pax-avaria-1.0.1-uber.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-mazovia/1.0.1/pax-mazovia-1.0.1-uber.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-novgorod/1.0.1/pax-novgorod-1.0.1-uber.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-castile/1.0.1/pax-castile-1.0.1-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-romana/1.0.0/pax-romana-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-hellenica/1.0.0/pax-hellenica-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-bohemia/1.0.0/pax-bohemia-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-pomerania/1.0.0/pax-pomerania-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-avaria/1.0.0/pax-avaria-1.0.0-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-mazovia/1.0.0/pax-mazovia-1.0.0-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-novgorod/1.0.0/pax-novgorod-1.0.0-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-castile/1.0.0/pax-castile-1.0.0-uber.jar"));
}
}
use of io.fabric8.knative.serving.v1.Service in project fabric8 by jboss-fuse.
the class ServiceImplTest method testPatch.
@Test
public void testPatch() throws Exception {
ComponentContext componentContext = createMock(ComponentContext.class);
BundleContext bundleContext = createMock(BundleContext.class);
Bundle sysBundle = createMock(Bundle.class);
BundleContext sysBundleContext = createMock(BundleContext.class);
Bundle bundle = createMock(Bundle.class);
Bundle bundle2 = createMock(Bundle.class);
FrameworkWiring wiring = createMock(FrameworkWiring.class);
GitPatchRepository repository = createMock(GitPatchRepository.class);
//
// Create a new service, download a patch
//
expect(componentContext.getBundleContext()).andReturn(bundleContext);
expect(bundleContext.getBundle(0)).andReturn(sysBundle).anyTimes();
expect(sysBundle.getBundleContext()).andReturn(sysBundleContext).anyTimes();
expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
expect(sysBundleContext.getProperty("karaf.data")).andReturn(karaf.getCanonicalPath() + "/data").anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
PatchManagement pm = mockManagementService(bundleContext);
((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
ServiceImpl service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
try {
service.download(new URL("file:" + storage + "/temp/f00.zip"));
fail("Should have thrown exception on non existent patch file.");
} catch (Exception e) {
}
Iterable<Patch> patches = service.download(patch132.toURI().toURL());
assertNotNull(patches);
Iterator<Patch> it = patches.iterator();
assertTrue(it.hasNext());
Patch patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.3.2", patch.getPatchData().getId());
assertNotNull(patch.getPatchData().getBundles());
assertEquals(1, patch.getPatchData().getBundles().size());
Iterator<String> itb = patch.getPatchData().getBundles().iterator();
assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
assertNull(patch.getResult());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
//
// Simulate the patch
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
expect(sysBundleContext.getServiceReference("io.fabric8.api.FabricService")).andReturn(null).anyTimes();
expect(bundle.getSymbolicName()).andReturn("my-bsn").anyTimes();
expect(bundle.getVersion()).andReturn(new Version("1.3.1")).anyTimes();
expect(bundle.getLocation()).andReturn("location").anyTimes();
expect(bundle.getBundleId()).andReturn(123L).anyTimes();
BundleStartLevel bsl = createMock(BundleStartLevel.class);
expect(bsl.getStartLevel()).andReturn(30).anyTimes();
expect(bundle.adapt(BundleStartLevel.class)).andReturn(bsl).anyTimes();
expect(bundle.getState()).andReturn(1);
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
PatchResult result = service.install(patch, true);
assertNotNull(result);
assertNull(patch.getResult());
assertTrue(result.isSimulation());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
//
// Recreate a new service and verify the downloaded patch is still available
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository, bsl);
expect(componentContext.getBundleContext()).andReturn(bundleContext);
expect(bundleContext.getBundle(0)).andReturn(sysBundle);
expect(sysBundle.getBundleContext()).andReturn(sysBundleContext);
expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository, bsl);
service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
patches = service.getPatches();
assertNotNull(patches);
it = patches.iterator();
assertTrue(it.hasNext());
patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.3.2", patch.getPatchData().getId());
assertNotNull(patch.getPatchData().getBundles());
assertEquals(1, patch.getPatchData().getBundles().size());
itb = patch.getPatchData().getBundles().iterator();
assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
assertNull(patch.getResult());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
//
// Install the patch
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
expect(sysBundleContext.getServiceReference("io.fabric8.api.FabricService")).andReturn(null).anyTimes();
expect(bundle.getSymbolicName()).andReturn("my-bsn").anyTimes();
expect(bundle.getVersion()).andReturn(new Version("1.3.1")).anyTimes();
expect(bundle.getLocation()).andReturn("location").anyTimes();
expect(bundle.getHeaders()).andReturn(new Hashtable<String, String>()).anyTimes();
expect(bundle.getBundleId()).andReturn(123L).anyTimes();
bundle.update(EasyMock.<InputStream>anyObject());
expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
expect(bundle.getState()).andReturn(Bundle.INSTALLED).anyTimes();
expect(bundle.getRegisteredServices()).andReturn(null);
expect(bundle.adapt(BundleStartLevel.class)).andReturn(bsl).anyTimes();
expect(bsl.getStartLevel()).andReturn(30).anyTimes();
expect(sysBundleContext.getBundle(0)).andReturn(sysBundle);
expect(sysBundle.adapt(FrameworkWiring.class)).andReturn(wiring);
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
bundle.start();
wiring.refreshBundles(eq(asSet(bundle)), anyObject(FrameworkListener[].class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
((FrameworkListener) (EasyMock.getCurrentArguments()[1])).frameworkEvent(null);
return null;
}
});
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bundle2, wiring, bsl);
result = service.install(patch, false);
assertNotNull(result);
assertSame(result, patch.getResult());
assertFalse(patch.getResult().isSimulation());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, wiring);
//
// Recreate a new service and verify the downloaded patch is still available and installed
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
expect(componentContext.getBundleContext()).andReturn(bundleContext);
expect(bundleContext.getBundle(0)).andReturn(sysBundle);
expect(sysBundle.getBundleContext()).andReturn(sysBundleContext);
expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
patches = service.getPatches();
assertNotNull(patches);
it = patches.iterator();
assertTrue(it.hasNext());
patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.3.2", patch.getPatchData().getId());
assertNotNull(patch.getPatchData().getBundles());
assertEquals(1, patch.getPatchData().getBundles().size());
itb = patch.getPatchData().getBundles().iterator();
assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
assertNotNull(patch.getResult());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
}
use of io.fabric8.knative.serving.v1.Service in project fabric8 by jboss-fuse.
the class ServiceFactoryTest method testDiscoveryOnRestartCurator.
@Test
public void testDiscoveryOnRestartCurator() throws Exception {
underTest = new ActiveMQServiceFactory();
underTest.curator = curator;
Properties props = new Properties();
props.put("config", "amq.xml");
props.put("broker-name", "amq");
props.put("group", "amq");
props.put("connectors", "openwire");
props.put("openwire-port", "0");
props.put("container.ip", "localhost");
underTest.updated("b", props);
final AtomicReference<CuratorFramework> curatorFrameworkAtomicReference = new AtomicReference<>(curator);
OsgiFabricDiscoveryAgent osgiFabricDiscoveryAgent = new OsgiFabricDiscoveryAgent(new BundleContext() {
@Override
public String getProperty(String s) {
return null;
}
@Override
public Bundle getBundle() {
return null;
}
@Override
public Bundle installBundle(String s, InputStream inputStream) throws BundleException {
return null;
}
@Override
public Bundle installBundle(String s) throws BundleException {
return null;
}
@Override
public Bundle getBundle(long l) {
return null;
}
@Override
public Bundle[] getBundles() {
return new Bundle[0];
}
@Override
public void addServiceListener(ServiceListener serviceListener, String s) throws InvalidSyntaxException {
}
@Override
public void addServiceListener(ServiceListener serviceListener) {
}
@Override
public void removeServiceListener(ServiceListener serviceListener) {
}
@Override
public void addBundleListener(BundleListener bundleListener) {
}
@Override
public void removeBundleListener(BundleListener bundleListener) {
}
@Override
public void addFrameworkListener(FrameworkListener frameworkListener) {
}
@Override
public void removeFrameworkListener(FrameworkListener frameworkListener) {
}
@Override
public ServiceRegistration<?> registerService(String[] strings, Object o, Dictionary<String, ?> dictionary) {
return null;
}
@Override
public ServiceRegistration<?> registerService(String s, Object o, Dictionary<String, ?> dictionary) {
return null;
}
@Override
public <S> ServiceRegistration<S> registerService(Class<S> aClass, S s, Dictionary<String, ?> dictionary) {
return null;
}
@Override
public ServiceReference<?>[] getServiceReferences(String s, String s1) throws InvalidSyntaxException {
return new ServiceReference<?>[0];
}
@Override
public ServiceReference<?>[] getAllServiceReferences(String s, String s1) throws InvalidSyntaxException {
return new ServiceReference<?>[0];
}
@Override
public ServiceReference<?> getServiceReference(String s) {
return null;
}
@Override
public <S> ServiceReference<S> getServiceReference(Class<S> aClass) {
return null;
}
@Override
public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> aClass, String s) throws InvalidSyntaxException {
return null;
}
@Override
public <S> S getService(ServiceReference<S> serviceReference) {
return (S) curatorFrameworkAtomicReference.get();
}
@Override
public boolean ungetService(ServiceReference<?> serviceReference) {
return false;
}
@Override
public File getDataFile(String s) {
return null;
}
@Override
public Filter createFilter(String s) throws InvalidSyntaxException {
return null;
}
@Override
public Bundle getBundle(String s) {
return null;
}
});
final LinkedBlockingQueue<DiscoveryEvent> discoveryEvents = new LinkedBlockingQueue<DiscoveryEvent>(10);
osgiFabricDiscoveryAgent.setDiscoveryListener(new DiscoveryListener() {
@Override
public void onServiceAdd(DiscoveryEvent discoveryEvent) {
discoveryEvents.offer(discoveryEvent);
}
@Override
public void onServiceRemove(DiscoveryEvent discoveryEvent) {
}
});
// will call into dummy bundle and get curator
osgiFabricDiscoveryAgent.addingService(null);
osgiFabricDiscoveryAgent.setGroupName("amq");
osgiFabricDiscoveryAgent.start();
DiscoveryEvent event = discoveryEvents.poll(5, TimeUnit.SECONDS);
LOG.info("event: " + event);
assertNotNull("got added service", event);
underTest.deleted("b");
// swap curator ref
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).sessionTimeoutMs(15000).retryPolicy(new RetryNTimes(5000, 1000));
curator = builder.build();
LOG.debug("Starting new curator " + curator);
curator.start();
curatorFrameworkAtomicReference.get().close();
curatorFrameworkAtomicReference.set(curator);
// will call into dummy bundle and get new curator ref
osgiFabricDiscoveryAgent.addingService(null);
// start broker again
underTest.curator = curator;
underTest.updated("b", props);
event = discoveryEvents.poll(5, TimeUnit.SECONDS);
LOG.info("new event: " + event);
assertNotNull("got newly added service", event);
underTest.deleted("b");
}
use of io.fabric8.knative.serving.v1.Service in project fabric8 by jboss-fuse.
the class GatewayServiceTreeCache method treeCacheEvent.
protected void treeCacheEvent(PathChildrenCacheEvent event) {
ChildData childData = event.getData();
if (childData == null) {
return;
}
String path = childData.getPath();
LOG.trace("Event {} on path {}", event.getType().toString(), path);
PathChildrenCacheEvent.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());
}
List<String> split = Strings.splitAndTrimAsList(path, "/");
// Lets just use the group name as the service path.
path = split.get(0);
String zNode = split.get(1);
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);
dto.setContainer(dto.getContainer() + "_zNode_" + zNode);
if (remove) {
LOG.info("Removed gateway service: " + path + ": " + dto);
serviceMap.serviceRemoved(path, dto);
} else {
LOG.info("Updated gateway service: " + path + ": " + dto);
serviceMap.serviceUpdated(path, 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.knative.serving.v1.Service in project fabric8 by jboss-fuse.
the class MappingConfigurationTest method addService.
protected void addService(String path, String service, String version) {
Map<String, String> params = new HashMap<String, String>();
params.put("version", version);
String container = path.contains("HelloWorld") ? "soapy" : "resty";
params.put("container", container);
ServiceDTO serviceDetails = new ServiceDTO();
serviceDetails.setContainer(container);
serviceDetails.setVersion(version);
config.updateMappingRules(false, path, Arrays.asList(service), params, serviceDetails);
}
Aggregations