use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class ProfileMetadata method findMetadataForProfile.
protected void findMetadataForProfile(String versionId, String profileId, MetadataHandler handler) throws Exception {
FabricService service = fabricService.get();
Objects.notNull(service, "FabricService");
ProfileService profileService = service.adapt(ProfileService.class);
Objects.notNull(profileService, "ProfileService");
DownloadManager downloadManager = DownloadManagers.createDownloadManager(service, executorService);
Objects.notNull(downloadManager, "DownloadManager");
Profile immediateProfile = profileService.getProfile(versionId, profileId);
Objects.notNull(immediateProfile, "Profile for versionId: " + versionId + ", profileId: " + profileId);
Profile profile = profileService.getOverlayProfile(immediateProfile);
Set<String> pids = new HashSet<>();
Map<String, File> fileMap = AgentUtils.downloadProfileArtifacts(service, downloadManager, profile);
Set<Map.Entry<String, File>> entries = fileMap.entrySet();
for (Map.Entry<String, File> entry : entries) {
String uri = entry.getKey();
File file = entry.getValue();
if (!file.exists() || !file.isFile()) {
LOG.warn("File " + file + " is not an existing file for " + uri + ". Ignoring");
continue;
}
addMetaTypeInformation(handler, uri, file);
pids.add(uri);
}
// lets check if the MetaType folder exists
if (metaTypeFolder != null && metaTypeFolder.exists() && metaTypeFolder.isDirectory()) {
Set<String> configurationFileNames = profile.getConfigurationFileNames();
for (String configName : configurationFileNames) {
if (configName.endsWith(PROPERTIES_SUFFIX) && configName.indexOf('/') < 0) {
String pid = configName.substring(0, configName.length() - PROPERTIES_SUFFIX.length());
addMetaTypeInformation(pids, handler, pid);
String factoryPid = getFactoryPid(pid);
addMetaTypeInformation(pids, handler, factoryPid);
}
}
}
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class FabricResource method setRequirements.
@POST
@Path("requirements")
public void setRequirements(FabricRequirements requirements) throws IOException {
Objects.notNull(requirements, "requirements");
FabricService service = getFabricService();
Objects.notNull(service, "FabricService");
service.setRequirements(requirements);
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class InvocationTest method testUnderLoadAsyncProto.
@Test(timeout = 30 * 1000)
public void testUnderLoadAsyncProto() throws Exception {
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
DispatchQueue queue = Dispatch.createQueue();
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
final HelloImpl helloImpl = new HelloImpl();
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return helloImpl;
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
final Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
final AtomicInteger requests = new AtomicInteger(0);
final AtomicInteger failures = new AtomicInteger(0);
final long[] latencies = new long[BENCHMARK_CLIENTS * BENCHMARK_INVOCATIONS_PER_CLIENT];
final long start = System.nanoTime();
AsyncClient[] threads = new AsyncClient[BENCHMARK_CLIENTS];
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t] = new AsyncClient(t, BENCHMARK_INVOCATIONS_PER_CLIENT, hello, failures, requests, latencies);
threads[t].start();
}
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t].join();
}
final long end = System.nanoTime();
long latency_sum = 0;
for (int t = 0; t < latencies.length; t++) {
if (latencies[t] != -1) {
latency_sum += latencies[t];
}
}
double latency_avg = ((latency_sum * 1.0d) / requests.get()) / MILLIS_IN_A_NANO;
double request_rate = ((requests.get() * 1.0d) / (end - start)) * SECONDS_IN_A_NANO;
System.err.println(String.format("Requests/Second: %,.2f", request_rate));
System.err.println(String.format("Average request latency: %,.2f ms", latency_avg));
System.err.println("Error Ratio: " + failures.get() + " / " + requests.get());
} finally {
server.stop();
client.stop();
}
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class InvocationTest method testOverflow.
@Test(timeout = 30 * 1000)
public void testOverflow() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
final Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
final AtomicInteger requests = new AtomicInteger(0);
final AtomicInteger responses = new AtomicInteger(0);
final AtomicInteger failures = new AtomicInteger(0);
char[] chars = new char[65 * 1024];
final String payload = new String(chars);
Thread[] threads = new Thread[BENCHMARK_CLIENTS];
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t] = new Thread() {
public void run() {
try {
requests.incrementAndGet();
hello.hello(payload);
responses.incrementAndGet();
} catch (Throwable t) {
failures.incrementAndGet();
}
}
};
threads[t].start();
}
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t].join(10000);
System.err.format("REQUEST: %d of %d%n", requests.get(), BENCHMARK_CLIENTS);
System.err.format("RESPONSES: %d of %d%n", responses.get(), BENCHMARK_CLIENTS);
assertEquals(threads[t].isAlive(), false);
}
assertEquals(BENCHMARK_CLIENTS, requests.get());
assertEquals(BENCHMARK_CLIENTS, responses.get());
assertEquals(0, failures.get());
} finally {
server.stop();
client.stop();
}
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class InvocationTest method testOverflowAsync.
@Test(timeout = 30 * 1000)
public void testOverflowAsync() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
char[] chars = new char[65 * 1024];
String payload = new String(chars);
final List<AsyncCallbackFuture<String>> futures = new ArrayList<AsyncCallbackFuture<String>>();
for (int i = 0; i < 100; i++) {
AsyncCallbackFuture<String> future = new AsyncCallbackFuture<String>();
hello.hello(payload, future);
futures.add(future);
}
for (Future<String> f : futures) {
f.get(3, TimeUnit.SECONDS);
}
// future2.get(2, TimeUnit.SECONDS);
// assertEquals("Hello Hiram!", future1.get(2, TimeUnit.SECONDS));
// assertEquals("Hello Hiram!", hello.protobuf(stringValue(payload)).getValue());
} finally {
server.stop();
client.stop();
}
}
Aggregations